Пример #1
0
 /**
  * Get entity by title
  *
  * @param  string $title
  * @param  array  $filters
  * @return \ArrayObject
  */
 public function getByTitle($title, array $filters = [])
 {
     $entity = Table\Entities::findBy(['title' => $title]);
     if (isset($entity->id)) {
         $this->getById($entity->id);
         if (class_exists('Phire\\Fields\\Model\\FieldValue')) {
             $entity = \Phire\Fields\Model\FieldValue::getModelObjectValues($this, null, $filters);
             $data = $entity->toArray();
             $this->data = array_merge($this->data, $data);
         }
     }
     return new \ArrayObject($this->data, \ArrayObject::ARRAY_AS_PROPS);
 }
Пример #2
0
 /**
  * Get content by date
  *
  * @param  string $date
  * @param  string $dateTimeFormat
  * @param  array  $filters
  * @param  string $limit
  * @param  string $page
  * @return array
  */
 public function getByDate($date, $dateTimeFormat, $filters, $limit = null, $page = null)
 {
     $sql1 = Table\Content::sql();
     $sql2 = clone $sql1;
     $sql2->select(['count' => 'COUNT(*)', 'in_date' => DB_PREFIX . 'content_types.in_date']);
     $sql1->select(['id' => DB_PREFIX . 'content.id', 'type_id' => DB_PREFIX . 'content.type_id', 'parent_id' => DB_PREFIX . 'content.parent_id', 'title' => DB_PREFIX . 'content.title', 'uri' => DB_PREFIX . 'content.uri', 'slug' => DB_PREFIX . 'content.slug', 'status' => DB_PREFIX . 'content.status', 'publish' => DB_PREFIX . 'content.publish', 'expire' => DB_PREFIX . 'content.expire', 'in_date' => DB_PREFIX . 'content_types.in_date']);
     $sql1->select()->join(DB_PREFIX . 'content_types', [DB_PREFIX . 'content_types.id' => DB_PREFIX . 'content.type_id']);
     $sql2->select()->join(DB_PREFIX . 'content_types', [DB_PREFIX . 'content_types.id' => DB_PREFIX . 'content.type_id']);
     $dateAry = explode('/', $date);
     if (count($dateAry) == 3) {
         $start = $dateAry[0] . '-' . $dateAry[1] . '-' . $dateAry[2] . ' 00:00:00';
         $end = $dateAry[0] . '-' . $dateAry[1] . '-' . $dateAry[2] . ' 23:59:59';
     } else {
         if (count($dateAry) == 2) {
             $start = $dateAry[0] . '-' . $dateAry[1] . '-01 00:00:00';
             $end = $dateAry[0] . '-' . $dateAry[1] . '-' . date('t', strtotime($dateAry[0] . '-' . $dateAry[1] . '-01')) . ' 23:59:59';
         } else {
             $start = $dateAry[0] . '-01-01 00:00:00';
             $end = $dateAry[0] . '-12-31 23:59:59';
         }
     }
     $sql1->select()->where('status = :status')->where('publish >= :publish1')->where('publish <= :publish2')->where('in_date = :in_date');
     $sql2->select()->where('status = :status')->where('publish >= :publish1')->where('publish <= :publish2')->where('in_date = :in_date');
     $params = ['status' => 1, 'publish' => [$start, $end], 'in_date' => 1];
     $count = Table\Content::execute((string) $sql2, $params)->count;
     if ($count > $limit) {
         $page = null !== $page && (int) $page > 1 ? $page * $limit - $limit : null;
         $sql1->select()->offset($page)->limit($limit);
     }
     $sql1->select()->orderBy('publish', 'DESC');
     $rows = Table\Content::execute((string) $sql1, $params)->rows();
     if (class_exists('Phire\\Fields\\Model\\FieldValue')) {
         foreach ($rows as $i => $row) {
             $fieldValues = \Phire\Fields\Model\FieldValue::getModelObjectValues('Phire\\Content\\Model\\Content', $row->id, $filters);
             $rows[$i] = new \ArrayObject(array_merge((array) $row->getColumns(), $fieldValues), \ArrayObject::ARRAY_AS_PROPS);
             $rows[$i]->publish = date($dateTimeFormat, strtotime($rows[$i]->publish));
         }
     }
     return $rows;
 }