Example #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;
 }