/**
  * Loads one or more entities.
  *
  * @param $ids
  *   An array of entity IDs, or FALSE to load all entities.
  * @param $conditions
  *   An array of conditions in the form 'field' => $value.
  *
  * @return
  *   An array of entity objects indexed by their ids. When no results are
  *   found, an empty array is returned.
  */
 public function load($ids = array(), $conditions = array())
 {
     // If not loading a specific revision, look for and load a revision matching
     // the currently active revision tag.
     if (($revision_id_key = $this->info['entity keys']['revision']) && empty($conditions[$revision_id_key])) {
         $data = new \StdClass();
         $data->base_id_key = $this->info['entity keys']['id'];
         $data->revision_id_key = $revision_id_key;
         $data->base_table = $this->info['base table'];
         $data->type = $this->type;
         $data->ids = $ids;
         if ($revision_ids = sps_drupal()->sps_get_manager()->react('entity_load', $data)) {
             $conditions[$revision_id_key] = $revision_ids;
         }
     }
     return $this->controller->load($ids, $conditions);
 }
 /**
  * Create a temp table of the override data we have
  *
  * @param $type
  *   the type of overrides that should be in the temp table
  *
  * @return 
  *   name of the temp table
  */
 protected function createTempTable($type)
 {
     $querys = array();
     foreach ($this->table as $row) {
         if ($row['type'] == $type) {
             $columns = array("{$row['id']} as id");
             foreach ($this->getPropertyMap() as $property => $field) {
                 $value = isset($row[$property]) ? $row[$property] : 'NULL';
                 $columns[] = "{$value} as {$field}";
             }
             $querys[] = "SELECT " . implode(",", $columns);
         }
     }
     // if we do not have any overrides we need to add a dummy one so that the temp table can be created
     if (empty($querys)) {
         $querys[] = "SELECT 0 as id, NULL as override_revision_id";
     }
     return sps_drupal()->db_query_temporary(implode(" UNION ", $querys));
 }
 /**
  * Validates this Conditions preview form.
  *
  * This function should use form_set_error() to mark any fields
  * which do not validate.
  *
  * @param $element
  *  The form portion (element) which should be validated
  * @param $form_state
  *  The full form_state for the form which is being built. Note
  *  that values my be treed as described by $elements #parent key
  *
  * @return
  *  Self
  */
 public function validateElement($element, &$form_state)
 {
     if ($this->validate_fail_message || $this->validate_fail_name) {
         sps_drupal()->form_set_error($this->validate_fail_name, $this->validate_fail_message);
     }
     return $this;
 }
Exemplo n.º 4
0
 /**
  * call a reaction rect method
  *
  * The manager is use as an interface for Drupal hooks that need to have a
  * reaction react
  *
  * ___________________
  * \                  \
  *  \  Manager::react  \
  *   ) called           )----Reaction Name and Data
  *  /                  /     |
  * /__________________/      |
  *            ^              v
  *            |      ______________
  *            |      \             \
  *            |       \  Check if   \
  *       On Admin Page-) on admin    )
  *            |       /             /
  *            |      /_____________/
  *            |              |
  *            |              v
  *            |      ______________
  *            |      \             \                        .------------------.
  *            |       \  Get Site   \                       | State Controller |
  *       No SiteState--) State       )--------------------->|------------------|
  *            |       /             / ^                     | get()            |
  *            |      /_____________/  |                     '------------------'
  *            |              |        |                               |
  *            |              v        '------SiteState object---------'
  *            |    _________________
  *            |    \                \
  *            |     \  Get Reaction  \
  *      No Reaction  ) ORC api key    )---------reaction name---------.
  *            |     /  and object    / ^                              v
  *            |    /________________/  |                    .-------------------.
  *            |              |         |                    | Plugin Controller |
  *            |              |         |                    |-------------------|
  *            |              |         |                    | getPluginInfo()   |
  *            |              |         |                    | getPlugin()       |
  *            |              |         |                    '-------------------'
  *            |              v         |                              |
  *            |    _________________   '--Override Controller API Key-'
  *            |    \                \     Reaction Object
  *            |     \  Get Override  \
  *          No ORC---) Controller     )-Override Controller API Key-.
  *            |     /                / ^                            v
  *            |    /________________/  |               .-------------------------.
  *            |              |         |               |       Site State        |
  *            |              |         |               |-------------------------|
  *            |              |         |               | getOverrideController() |
  *            |              |         |               '-------------------------'
  *            |              |         |                            |
  *            |              v         '-OverrideController object -'
  *            |        _________
  *            |        \        \
  *            |         \  Call  \
  *     retrun data-------) React  )---data and OverrideController obj-.
  *                      /        /                                    v
  *                     /________/                           .------------------.
  *                           ^                              |     Reaction     |
  *                           |                              |------------------|
  *                           |                              | react()          |
  *                           |                              '------------------'
  *                           |                                        |
  *                           '--------return data---------------------'
  *
  *
  * @param String $reaction
  *   the name of a reaction plugin;
  * @param mixed $data
  *   data to be passed to the react method
  *
  * @return mixed
  *   Data used by the item calling reaction
  */
 public function react($reaction, $data)
 {
     $infos = $this->getActiveReactionInfo();
     if (isset($infos[$reaction]) && ($site_state = $this->getSiteState()) && ($controller = $site_state->getOverrideController($infos[$reaction]['use_controller_api']))) {
         // Calling path_is_admin() to early can lead to cache poisoning of
         // entity_get_info() - which means a whole bunch of entity information is
         // missing. Thus check it as separated final condition.
         // @TODO Find a better way to deal with this. This is just a lucky shot
         // and not a proper solution.
         if (!sps_drupal()->path_is_admin(sps_drupal()->current_path())) {
             return $this->getPlugin("reaction", $reaction)->react($data, $controller);
         }
     }
 }
Exemplo n.º 5
0
 /**
  * call a reaction rect method
  *
  * The manager is use as an interface for Drupal hooks that need to have a
  * reaction react
  *
  * ___________________
  * \                  \
  *  \  Manager::react  \
  *   ) called           )----Reaction Name and Data
  *  /                  /     |
  * /__________________/      |
  *            ^              v
  *            |      ______________
  *            |      \             \
  *            |       \  Check if   \
  *       On Admin Page-) on admin    )
  *            |       /             /
  *            |      /_____________/
  *            |              |
  *            |              v
  *            |      ______________
  *            |      \             \                        .------------------.
  *            |       \  Get Site   \                       | State Controller |
  *       No SiteState--) State       )--------------------->|------------------|
  *            |       /             / ^                     | get()            |
  *            |      /_____________/  |                     '------------------'
  *            |              |        |                               |
  *            |              v        '------SiteState object---------'
  *            |    _________________
  *            |    \                \
  *            |     \  Get Reaction  \
  *      No Reaction  ) ORC api key    )---------reaction name---------.
  *            |     /  and object    / ^                              v
  *            |    /________________/  |                    .-------------------.
  *            |              |         |                    | Plugin Controller |
  *            |              |         |                    |-------------------|
  *            |              |         |                    | getPluginInfo()   |
  *            |              |         |                    | getPlugin()       |
  *            |              |         |                    '-------------------'
  *            |              v         |                              |
  *            |    _________________   '--Override Controller API Key-'
  *            |    \                \     Reaction Object
  *            |     \  Get Override  \
  *          No ORC---) Controller     )-Override Controller API Key-.
  *            |     /                / ^                            v
  *            |    /________________/  |               .-------------------------.
  *            |              |         |               |       Site State        |
  *            |              |         |               |-------------------------|
  *            |              |         |               | getOverrideController() |
  *            |              |         |               '-------------------------'
  *            |              |         |                            |
  *            |              v         '-OverrideController object -'
  *            |        _________
  *            |        \        \
  *            |         \  Call  \
  *     retrun data-------) React  )---data and OverrideController obj-.
  *                      /        /                                    v
  *                     /________/                           .------------------.
  *                           ^                              |     Reaction     |
  *                           |                              |------------------|
  *                           |                              | react()          |
  *                           |                              '------------------'
  *                           |                                        |
  *                           '--------return data---------------------'
  *
  *
  * @param String $reaction
  *   the name of a reaction plugin;
  * @param mixed $data
  *   data to be passed to the react method
  *
  * @return mixed
  *   Data used by the item calling reaction
  */
 public function react($reaction, $data)
 {
     $infos = $this->getActiveReactionInfo();
     if (isset($infos[$reaction]) && !sps_drupal()->path_is_admin(sps_drupal()->current_path()) && ($site_state = $this->getSiteState()) && ($controller = $site_state->getOverrideController($infos[$reaction]['use_controller_api']))) {
         return $this->getPlugin("reaction", $reaction)->react($data, $controller);
     }
 }