ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilFileDataShop.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
11 require_once './Services/FileSystem/classes/class.ilFileData.php';
12 
14 {
15  const SHOPPATH = 'shop';
16 
17  private $pobject_id = 0;
18  private $shop_path = '';
19  private $image_current = '';
20  private $image_new = '';
21  private $db = null;
22 
23  public function __construct($a_pobject_id)
24  {
25  global $ilDB;
26 
27  $this->db = $ilDB;
28  $this->pobject_id = $a_pobject_id;
29 
31  $this->shop_path = ilUtil::getWebspaceDir().'/'.self::SHOPPATH.'/'.$this->pobject_id;
32  $this->initDirectory();
33  $this->checkReadWrite();
34 
35  $this->__read();
36  }
37 
38  private function __read()
39  {
40  $result = $this->db->queryf('SELECT image FROM payment_objects WHERE pobject_id = %s',
41  array('integer'),array($this->pobject_id));
42 
43  while($record = $this->db->fetchAssoc($result))
44  {
45  $this->image_current = $record['image'];
46  break;
47  }
48  }
49 
50  public function getCurrentImageWebPath()
51  {
52  if($this->image_current != '' &&
53  $this->checkFilesExist(array($this->image_current)))
54  {
55  return ilUtil::getWebspaceDir('output').'/'.self::SHOPPATH.'/'.$this->pobject_id.'/'.$this->image_current;
56  }
57 
58  return false;
59  }
60 
61  public function getCurrentImageServerPath()
62  {
63  if($this->image_current != "" &&
64  $this->checkFilesExist(array($this->image_current)))
65  {
66  return $this->shop_path.'/'.$this->image_current;
67  }
68 
69  return false;
70  }
71 
72  private function initDirectory()
73  {
74  if(is_writable($this->getPath()))
75  {
76  if(ilUtil::makeDirParents($this->shop_path))
77  {
78  return true;
79  }
80  }
81 
82  return false;
83  }
84 
85  private function checkReadWrite()
86  {
87  if(is_writable($this->shop_path) && is_readable($this->shop_path))
88  {
89  return true;
90  }
91  else
92  {
93  $this->ilias->raiseError('Shop directory is not readable/writable by webserver', $this->ilias->error_obj->FATAL);
94  }
95  }
96 
97  public function storeUploadedFile($a_http_post_file)
98  {
99  if($this->image_current != '') $this->unlinkFile($this->image_current);
100 
101  if(isset($a_http_post_file) && $a_http_post_file['size'])
102  {
103  if(ilUtil::moveUploadedFile($a_http_post_file['tmp_name'], $a_http_post_file['name'],
104  $this->shop_path.'/'.$a_http_post_file['name']))
105  {
106  ilUtil::resizeImage('"'.$this->shop_path.'/'.$a_http_post_file['name'].'"', '"'.$this->shop_path.'/'.$a_http_post_file['name'].'"', 100, 75);
107  return $this->image_new = $a_http_post_file['name'];
108 
109  }
110  }
111 
112  return false;
113  }
114 
115  public function assignFileToPaymentObject()
116  {
117  $statement = $this->db->manipulateF(
118  'UPDATE payment_objects
119  SET
120  image = %s
121  WHERE pobject_id = %s',
122  array('text', 'integer'),
123  array($this->image_new, $this->pobject_id));
124 
125 
126  $this->image_current = $this->image_new;
127 
128  return true;
129  }
130 
132  {
133  $statement = $this->db->manipulateF(
134  'UPDATE payment_objects
135  SET
136  image = %s
137  WHERE pobject_id = %s',
138  array('text', 'integer'),
139  //array('', $this->pobject_id));
140  array(NULL, $this->pobject_id));
141 
142  if($this->image_current != '') $this->unlinkFile($this->image_current);
143  ilUtil::delDir($this->shop_path);
144  $this->image_current = '';
145 
146  return true;
147  }
148 
149 
150  public function unlinkFile($a_filename)
151  {
152  if(file_exists($this->shop_path.'/'.$a_filename))
153  {
154  return unlink($this->shop_path.'/'.$a_filename);
155  }
156  }
157 
158  public function checkFilesExist($a_files)
159  {
160  if($a_files)
161  {
162  foreach($a_files as $file)
163  {
164  if(!file_exists($this->shop_path.'/'.$file))
165  {
166  return false;
167  }
168  }
169  return true;
170  }
171  return true;
172  }
173 }
174 ?>