示例#1
0
 public function get(array $ids = NULL)
 {
     $agent = $this->_section->agent();
     $fids = $this->active_fields();
     $documents = array();
     $results = array('total' => 0, 'documents' => array());
     $pagination = $this->pagination($ids);
     $query = $agent->get_query_props(array_keys($fids), (array) $this->sorting())->select('d.created_on')->select('d.created_by_id')->select('dss.name')->join(array('datasources', 'dss'))->on('d.ds_id', '=', 'dss.id');
     if (!empty($ids)) {
         $query->where('d.id', 'in', $ids);
     }
     $query = $this->search_by_keyword($query);
     $result = $query->limit($this->limit())->offset($this->offset())->execute()->as_array('id');
     if (count($result) > 0) {
         $results['total'] = $pagination->total_items;
         foreach ($result as $id => $row) {
             $data = array('id' => $id, 'published' => (bool) $row['published'], 'header' => $row['header'], 'created_on' => Date::format($row['created_on']), 'created_by_id' => $row['created_by_id']);
             foreach ($fids as $field) {
                 if (isset($row[$field->id])) {
                     $data[$field->name] = $field->fetch_headline_value($row[$field->id], $id);
                 }
             }
             $document = new DataSource_Hybrid_Document($this->_section);
             $document->id = $id;
             $documents[$id] = $document->read_values($data)->set_read_only();
         }
         $results['documents'] = $documents;
     }
     return $results;
 }
示例#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;
 }
示例#3
0
文件: images.php 项目: ortodesign/cms
 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, '');
     }
 }
示例#4
0
文件: array.php 项目: ortodesign/cms
 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);
     }
 }
示例#5
0
文件: text.php 项目: ortodesign/cms
 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));
         }
     }
 }
示例#6
0
文件: user.php 项目: ortodesign/cms
 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);
 }
示例#7
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);
 }
示例#8
0
 public function onUpdateDocument(DataSource_Hybrid_Document $old = NULL, DataSource_Hybrid_Document $new)
 {
     $new->set($this->name, $new->get($this->name) ? 1 : 0);
 }
示例#9
0
文件: file.php 项目: ZerGabriel/cms-1
 /**
  * 
  * @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, '');
     }
 }
示例#10
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;
 }
示例#11
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));
         }
     }
 }
示例#12
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);
 }
示例#13
0
 public function onRemoveDocument(DataSource_Hybrid_Document $doc)
 {
     if ($this->one_to_one) {
         DataSource_Hybrid_Factory::remove_documents($doc->get($this->name));
     }
 }
示例#14
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));
 }