Ejemplo n.º 1
0
 /**
  * Returns result of DELETE query stored in the template
  *
  * @param $moduleName
  * @param $templateName
  * @param array $params
  *
  * @return int
  */
 public function delete($moduleName, $templateName, $params = array())
 {
     $query = TextProcessor::doSqlTemplate($moduleName, $templateName, $params);
     return $this->runQuery($query);
 }
Ejemplo n.º 2
0
 /**
  * Returns result of select query in one of supported format
  *
  * @param array $searchParameters
  * @param array $options
  *
  * @return array
  */
 public function select($searchParameters = array(), $options = array())
 {
     $format = Util::lavnn('format', $options, 'array');
     $sorting = Util::lavnn('sort', $options, '');
     $sqlFileName = get_class($this) . '_Search';
     if (Locator::moduleFileExists($this->moduleName, "sql/{$sqlFileName}.sql")) {
         // We can override default search behaviour with custom SQL
         $query = TextProcessor::doSqlTemplate($this->moduleName, $sqlFileName, $searchParameters);
     } else {
         $where = $this->prepareWhere($searchParameters, $this->getMetadata(), __METHOD__);
         $sqlParams = array('tableName' => $this->tableName, 'whereClause' => count($where) ? 'WHERE ' . join(' AND ', $where) : '', 'orderClause' => $sorting != '' ? 'ORDER BY ' . $sorting : '');
         $query = TextProcessor::doText(file_get_contents(__DIR__ . "/Templates/Search.sql"), $sqlParams);
     }
     return $this->selectByQuery($query, $format);
 }
Ejemplo n.º 3
0
 /**
  * Returns ID of identity field affected by INSERT query stored in the template
  *
  * @param $moduleName
  * @param $templateName
  * @param array $params
  *
  * @return int
  */
 public function getNewID($moduleName, $templateName, $params = array())
 {
     $query = TextProcessor::doSqlTemplate($moduleName, $templateName, $params);
     $result = $this->runQuery($query);
     return $result['result'] == 'OK' ? $this->db->insert_id : -1;
 }