Beispiel #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));
         }
     }
 }
Beispiel #2
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, '');
     }
 }
Beispiel #3
0
 public function onRemoveDocument(DataSource_Hybrid_Document $doc)
 {
     $ids = explode(',', $doc->get($this->name));
     $this->delete_related_docs($doc->id);
     if ($this->one_to_many and !empty($ids)) {
         DataSource_Hybrid_Factory::remove_documents($ids);
     }
 }
Beispiel #4
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);
 }
Beispiel #5
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);
 }
Beispiel #6
0
 public function onUpdateDocument(DataSource_Hybrid_Document $old = NULL, DataSource_Hybrid_Document $new)
 {
     $new->set($this->name, $new->get($this->name) ? 1 : 0);
 }
Beispiel #7
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, '');
     }
 }
Beispiel #8
0
 /**
  * Шаблон поля, используемый при редактрировании документа.
  * 
  * @param string $template
  * @param DataSource_Hybrid_Document $document
  * @return View
  */
 public function backend_template(DataSource_Hybrid_Document $document, $template = NULL)
 {
     if ($template === NULL) {
         $template = 'datasource/hybrid/document/fields/' . $this->type;
     }
     return View::factory($template, array('value' => $document->get($this->name), 'field' => $this, 'document' => $document));
 }
Beispiel #9
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));
         }
     }
 }
Beispiel #10
0
 /**
  * 
  * @param Validation $validation
  * @param DataSource_Hybrid_Document $doc
  * @return Validation
  */
 public function onValidateDocument(Validation $validation, DataSource_Hybrid_Document $doc)
 {
     $image = $doc->get($this->name);
     $url = $doc->get($this->name . '_url');
     $from_url = FALSE;
     if (Valid::url($url)) {
         $from_url = TRUE;
     }
     if ($this->isreq === TRUE and $from_url === FALSE) {
         if (is_array($image)) {
             $validation->rules($this->name, array(array('Upload::not_empty')));
         } else {
             $validation->rules($this->name, array(array('not_empty')));
         }
     } elseif ($this->isreq === TRUE and $from_url === TRUE) {
         $validation->rules($this->name . '_url', array(array('not_empty')));
     }
     if ($from_url === FALSE and is_array($image)) {
         $validation->rules($this->name, array(array('Upload::valid'), array('Upload::type', array(':value', $this->types)), array('Upload::size', array(':value', $this->max_size))));
     } else {
         if ($from_url === TRUE) {
             $ext = strtolower(pathinfo($url, PATHINFO_EXTENSION));
             $validation->rules($this->name . '_url', array(array('url'), array('in_array', array($ext, $this->types))));
         }
     }
     return $validation->label($this->name . '_url', $this->header)->label($this->name, $this->header);
 }
Beispiel #11
0
 public function onRemoveDocument(DataSource_Hybrid_Document $doc)
 {
     if ($this->one_to_one) {
         DataSource_Hybrid_Factory::remove_documents($doc->get($this->name));
     }
 }
Beispiel #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));
 }