Ejemplo n.º 1
0
 public function onUpdateDocument(DataSource_Hybrid_Document $old = NULL, DataSource_Hybrid_Document $new)
 {
     if ($this->allow_html === FALSE) {
         $new->set($this->name, strip_tags($new->get($this->name)));
     } else {
         if ($this->filter_html === TRUE) {
             $new->set($this->name, Kses::filter($new->get($this->name), $this->allowed_tags));
         }
     }
 }
Ejemplo n.º 2
0
 public function onReadDocumentValue(array $data, DataSource_Hybrid_Document $document)
 {
     $value = Arr::get($data, $this->name);
     $value = (int) preg_replace('/[^\\d]/', '', $value);
     $document->set($this->name, $value);
     return $this;
 }
Ejemplo n.º 3
0
 public function onRemoveDocument(DataSource_Hybrid_Document $doc)
 {
     $ids = $doc->get($this->name);
     if (!empty($ids)) {
         ORM::factory('media')->delete_by_ids(explode(',', $ids));
         $doc->set($this->name, '');
     }
 }
Ejemplo n.º 4
0
 public function onUpdateDocument(DataSource_Hybrid_Document $old = NULL, DataSource_Hybrid_Document $new)
 {
     if ($new->get($this->name) == -1) {
         if ($this->one_to_one) {
             DataSource_Hybrid_Factory::remove_documents($old->get($this->name));
         }
         $new->set($this->name, NULL);
         return;
     }
 }
Ejemplo n.º 5
0
 public function onUpdateDocument(DataSource_Hybrid_Document $old = NULL, DataSource_Hybrid_Document $new)
 {
     $user_id = $new->get($this->name);
     if ($this->only_current === TRUE) {
         $user_id = $old->get($this->name);
     }
     if (!$this->is_exists($user_id)) {
         $user_id = 0;
     }
     $new->set($this->name, $user_id);
 }
Ejemplo n.º 6
0
 public function onUpdateDocument(DataSource_Hybrid_Document $old = NULL, DataSource_Hybrid_Document $new)
 {
     $value = $new->get($this->name);
     if (is_array($value)) {
         if (!empty($value[0]) and !empty($value[1])) {
             $value = implode(',', $value);
         } else {
             $value = '';
         }
     }
     $new->set($this->name, $value);
 }
Ejemplo n.º 7
0
 public function onUpdateDocument(DataSource_Hybrid_Document $old = NULL, DataSource_Hybrid_Document $new)
 {
     $new->set($this->name, $new->get($this->name) ? 1 : 0);
 }
Ejemplo n.º 8
0
 /**
  * 
  * @param DataSource_Hybrid_Document $doc
  */
 public function onRemoveDocument(DataSource_Hybrid_Document $doc)
 {
     $value = $doc->get($this->name);
     if (!empty($value)) {
         @unlink(PUBLICPATH . $value);
         $doc->set($this->name, '');
     }
 }
Ejemplo n.º 9
0
 /**
  * В момент присвоения полям документа значений происходит обход массива
  * полей документа и в каждом поле вызов этого метода. Т.е. присвоение значений
  * происходит в этом методе, присвоение происходит до валидации данных.
  * 
  * @see DataSource_Hybrid_Document::read_values()
  * @see DataSource_Hybrid_Document::read_files()
  * 
  * @param array $data
  * @param DataSource_Hybrid_Document $doc
  * @return \DataSource_Hybrid_Field
  */
 public function onReadDocumentValue(array $data, DataSource_Hybrid_Document $document)
 {
     $document->set($this->name, Arr::get($data, $this->name));
     return $this;
 }
Ejemplo n.º 10
0
 public function onUpdateDocument(DataSource_Hybrid_Document $old = NULL, DataSource_Hybrid_Document $new)
 {
     $value = (int) $new->get($this->name);
     if (array_key_exists($value, $this->_options) or $this->custom_option === TRUE and !empty($value)) {
         $new->set($this->name, $value);
     } else {
         if ($value == 0 and $this->empty_value === TRUE) {
             $new->set($this->name, '');
         } else {
             $new->set($this->name, $old->get($this->name));
         }
     }
 }
Ejemplo n.º 11
0
 /**
  * 
  * @param DataSource_Hybrid_Document $old
  * @param DataSource_Hybrid_Document $new
  * @return boolean
  */
 public function onUpdateDocument(DataSource_Hybrid_Document $old = NULL, DataSource_Hybrid_Document $new)
 {
     $url = $new->get($this->name . '_url');
     $status = FALSE;
     if (Valid::url($url)) {
         $url = $new->get($this->name . '_url');
         $filename = Upload::from_url($url, $this->folder(), NULL, $this->types);
         if (!empty($filename)) {
             $this->_filepath = $this->folder() . $filename;
             $this->onRemoveDocument($old);
             $new->set($this->name, $this->folder . $filename);
             $status = TRUE;
         }
     } else {
         $status = parent::onUpdateDocument($old, $new);
     }
     if ($status !== TRUE) {
         return $status;
     }
     $image = Image::factory($this->_filepath);
     $width = (int) $this->width;
     $height = (int) $this->height;
     $crop = (bool) $this->crop;
     if ($width > 0 or $height > 0) {
         $image->resize($width, $height, $this->master);
         if ($crop === TRUE) {
             $image->crop($width, $height);
         }
     }
     if ($this->watermark === TRUE and $this->watermark_path !== NULL) {
         $watermark = Image::factory(DOCROOT . $this->watermark_path);
         $image->watermark($watermark, $this->watermark_offset_x, $this->watermark_offset_y, $this->watermark_opacity);
     }
     $image->save(NULL, $this->quality);
     return $status;
 }
Ejemplo n.º 12
0
 public function onUpdateDocument(DataSource_Hybrid_Document $old = NULL, DataSource_Hybrid_Document $new)
 {
     $new->set($this->name, Num::format($new->get($this->name), $this->after_coma_num));
 }