예제 #1
0
 /**
  * Includes the images assigned to the records.
  *
  * The `image` property of the records is set to the associated image.
  *
  * @param array $records The records to alter.
  *
  * @return array
  */
 public function including_assigned_image(array $records)
 {
     $keys = array();
     foreach ($records as $record) {
         $keys[] = $record->nid;
     }
     if (!$keys) {
         return;
     }
     $pairs = ActiveRecord\get_model('registry/node')->select('targetid, value')->filter_by_name_and_targetid('image_id', $keys)->pairs;
     try {
         $images = $this->find($pairs);
     } catch (RecordNotFound $e) {
         $images = $e->records;
     }
     foreach ($records as $record) {
         $nid = $record->nid;
         $image_key = $pairs[$nid];
         if (empty($images[$image_key])) {
             continue;
         }
         $record->image = $images[$image_key];
     }
     return $records;
 }
예제 #2
0
 public function alter_query_with_value(Query $query, $value)
 {
     $token = self::generate_token();
     $v_alias = $token . '_v';
     $t_alias = $token . '_t';
     $q = ActiveRecord\get_model('taxonomy.vocabulary')->select("nid, vocabularyslug AS {$v_alias}, termslug AS {$t_alias}")->join(':taxonomy.terms')->join(':taxonomy.terms/nodes');
     $query->join($q, ['on' => 'nid'])->where([$v_alias => $this->id, $t_alias => $value]);
     return $query;
 }
예제 #3
0
 /**
  * Finds the nodes the records belong to.
  *
  * The `node` property of the records is set to the node they belong to.
  *
  * @param array $records
  *
  * @return array
  */
 public function including_node(array $records)
 {
     $keys = array();
     foreach ($records as $record) {
         $keys[$record->nid] = $record;
     }
     $nodes = ActiveRecord\get_model('nodes')->find_using_constructor(array_keys($keys));
     foreach ($nodes as $key => $node) {
         $keys[$key]->node = $node;
     }
     return $records;
 }
예제 #4
0
 /**
  * Returns the photos associated with the album.
  *
  * @return array[]Photo
  */
 protected function lazy_get_photos()
 {
     $records = ActiveRecord\get_model('images.albums/photos')->filter_by_nid($this->nid)->order('weight')->all;
     #
     $keys = array();
     foreach ($records as $record) {
         $keys[$record->image_id] = $record;
     }
     if ($keys) {
         $images = ActiveRecord\get_model('images')->find_using_constructor(array_keys($keys));
         foreach ($images as $key => $image) {
             $keys[$key]->image = $image;
         }
     }
     return $records;
 }
예제 #5
0
 protected function lazy_get_model()
 {
     return ActiveRecord\get_model('images.albums/photos');
 }
예제 #6
0
 /**
  * Returns the {@link Site} instance associated with the node.
  *
  * @return Site
  */
 protected function get_site()
 {
     return $this->siteid ? ActiveRecord\get_model('sites')->find($this->siteid) : null;
 }
예제 #7
0
 /**
  * Returns the image associated with the photo.
  *
  * @return \Icybee\Modules\Images\Image|null Returns the associated image or `null` if there
  * is no image associated.
  */
 protected function lazy_get_image()
 {
     return $this->image_id ? ActiveRecord\get_model('images')->find($this->image_id) : null;
 }
예제 #8
0
 /**
  * Deletes the metadatas associated with a record when it is deleted.
  *
  * @param \ICanBoogie\Operation\ProcessEvent $event
  * @param \ICanBoogie\DeleteOperation $operation
  *
  * @throws \Exception
  */
 public static function on_operation_delete(\ICanBoogie\Operation\ProcessEvent $event, \ICanBoogie\DeleteOperation $operation)
 {
     $module = $operation->module;
     $type = self::resolve_type($module);
     ActiveRecord\get_model('registry/' . $type)->filter_by_targetid($operation->key)->delete();
 }
예제 #9
0
 protected function get_results()
 {
     return ActiveRecord\get_model('forms.blueprints/results')->filter_by_nid($this->nid)->order('created_at')->all;
 }
예제 #10
0
 /**
  * Finds the users the records belong to.
  *
  * The `user` property of the records is set to the user they belong to.
  *
  * @param array $records
  *
  * @return array
  */
 public function including_user(array $records)
 {
     $keys = [];
     foreach ($records as $record) {
         $keys[$record->uid] = $record;
     }
     $users = ActiveRecord\get_model('users')->find_using_constructor(array_keys($keys));
     /* @var $user \Icybee\Modules\Users\User */
     foreach ($users as $key => $user) {
         $keys[$key]->user = $user;
     }
     return $records;
 }