/** * 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; }
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; }
/** * 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; }
/** * 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; }
protected function lazy_get_model() { return ActiveRecord\get_model('images.albums/photos'); }
/** * 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; }
/** * 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; }
/** * 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(); }
protected function get_results() { return ActiveRecord\get_model('forms.blueprints/results')->filter_by_nid($this->nid)->order('created_at')->all; }
/** * 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; }