/**
  * Пересчитывает счетчики голосований
  *
  * @return bool
  */
 public function RecalculateVote()
 {
     $sql = "\n                UPDATE " . Config::Get('db.table.lsgallery.image') . " i\n                SET i.image_count_vote_up = (\n                    SELECT count(*)\n                    FROM " . Config::Get('db.table.vote') . " v\n                    WHERE\n                        v.target_id = i.image_id\n                    AND\n                        v.vote_direction = 1\n                    AND\n                        v.target_type = 'image'\n                ), i.image_count_vote_down = (\n                    SELECT count(*)\n                    FROM " . Config::Get('db.table.vote') . " v\n                    WHERE\n                        v.target_id = i.image_id\n                    AND\n                        v.vote_direction = -1\n                    AND\n                        v.target_type = 'image'\n                ), i.image_count_vote_abstain = (\n                    SELECT count(*)\n                    FROM " . Config::Get('db.table.vote') . " v\n                    WHERE\n                        v.target_id = i.image_id\n                    AND\n                        v.vote_direction = 0\n                    AND\n                        v.target_type = 'image'\n                ), i.image_count_vote = (\n                    SELECT count(*)\n                    FROM " . Config::Get('db.table.vote') . " v\n                    WHERE\n                        v.target_id = i.image_id\n                    AND\n                        v.target_type = 'image'\n                )\n            ";
     if ($this->oDb->query($sql)) {
         return true;
     }
     return false;
 }
 protected function _authenticate()
 {
     try {
         $resultIdentities = $this->_db->select($this->_sql, $this->_credential, $this->_identity);
     } catch (Exception $e) {
         /**
          * @see Zend_Auth_Adapter_Exception
          */
         require_once 'Zend/Auth/Adapter/Exception.php';
         $exception = 'The supplied parameters to ' . __CLASS__ . 'failed to produce a valid sql statement, please ' . 'check table and column names for validity.';
         throw new Zend_Auth_Adapter_Exception($exception);
     }
     return $resultIdentities;
 }
 /**
  * Загружает зависимости $subItemName для данной сущности
  * @param $subItemName
  * return bool
  */
 function loadRelated($subItemName, $fk = null)
 {
     if (method_exists($this, "load{$subItemName}")) {
         return call_user_func(array($this, "load{$subItemName}"));
     } else {
         $tableName = Lms_Item::getTableName($subItemName);
         if ($fk === null) {
             $fk = $this->_getSimplePk();
         }
         $fkValue = $this->__getValue($fk);
         $rows = $this->_slaveDb->select("SELECT * FROM {$tableName} WHERE ?#=?", $fk, $fkValue);
         if ($rows) {
             $subItemPk = Lms_Item::getStruct($subItemName)->getPk();
             foreach ($rows as $row) {
                 $scalarPkValue = Lms_Item_Scalar::extractScalarPkValue($row, $subItemPk);
                 Lms_Item_Store::setValues($tableName, $scalarPkValue, $row, true);
             }
             Lms_Item_Store::rebuildIndex($tableName);
         }
     }
 }
 /**
  * This method accepts a Zend_Db_Select object and
  * performs a query against the database with that object.
  *
  * @param Zend_Db_Select $dbSelect
  * @return array
  */
 protected function _authenticateQuerySelect($dbSelect)
 {
     $resultIdentities = $this->_db->select($dbSelect, $this->_credential, $this->_identity);
     return $resultIdentities;
 }