Esempio n. 1
0
 /**
  * Fetch the next result row and create the model
  * 
  * @return boolean True if there was another row
  */
 protected function fetchNext()
 {
     if ($this->objResult->next() == false) {
         return false;
     }
     $strClass = $this->getModelClassFromTable($this->strTable);
     $this->arrModels[$this->intIndex + 1] = new $strClass($this->objResult);
     return true;
 }
Esempio n. 2
0
 /**
  * Convert the database result into a proper result array.
  *
  * @param \Database\Result $values      The database result.
  *
  * @param string           $aliasColumn The name of the alias column to be used.
  *
  * @param string           $valueColumn The name of the value column.
  *
  * @param array            $count       The optional count array.
  *
  * @return array
  */
 protected function convertOptionsList($values, $aliasColumn, $valueColumn, &$count = null)
 {
     $arrReturn = array();
     while ($values->next()) {
         if (is_array($count)) {
             /** @noinspection PhpUndefinedFieldInspection */
             $count[$values->{$aliasColumn}] = $values->mm_count;
         }
         $arrReturn[$values->{$aliasColumn}] = $values->{$valueColumn};
     }
     return $arrReturn;
 }
Esempio n. 3
0
 /**
  * Create array of models and return a collection of them
  *
  * @param   \Database\Result $objResult
  * @param   string           $strTable
  *
  * @return  \Model\Collection
  */
 protected static function createCollectionFromDbResult(\Database\Result $objResult, $strTable = null)
 {
     // @deprecated Remove in Isotope 3.0 (only for backward compatibility Isotope < 2.1.2)
     if (null === $strTable) {
         $strTable = static::$strTable;
     }
     $arrModels = array();
     while ($objResult->next()) {
         // @deprecated use static::createModelFromDbResult once we drop BC support for buildModelType
         $objModel = static::buildModelType($objResult);
         if (null !== $objModel) {
             $arrModels[] = $objModel;
         }
     }
     return new \Model\Collection($arrModels, $strTable);
 }
 /**
  * Run the tests on a table
  *
  * @param string $table
  * @param Result $records
  *
  * @return array
  */
 protected function runTests($table, Result $records)
 {
     System::loadLanguageFile('seo_serp_tests');
     $result = ['errors' => 0, 'warnings' => 0];
     /** @var TestInterface $test */
     foreach (TestsManager::getAll() as $test) {
         // Skip the unsupported tests
         if (!$test->supports($table)) {
             continue;
         }
         while ($records->next()) {
             try {
                 $test->run($records->row(), $table);
             } catch (ErrorException $e) {
                 $result['errors']++;
             } catch (WarningException $e) {
                 $result['warnings']++;
             }
         }
         $records->reset();
     }
     return $result;
 }
 /**
  * Create a new collection from a database result
  *
  * @param \Database\Result $objResult The database result object
  * @param string           $strTable  The table name
  *
  * @return static The model collection
  */
 public static function createFromDbResult(\Database\Result $objResult, $strTable)
 {
     $arrModels = array();
     $strClass = \Model::getClassFromTable($strTable);
     while ($objResult->next()) {
         /** @var \Model $strClass */
         $objModel = \Model\Registry::getInstance()->fetch($strTable, $objResult->{$strClass::getPk()});
         if ($objModel !== null) {
             $objModel->mergeRow($objResult->row());
             $arrModels[] = $objModel;
         } else {
             $arrModels[] = new $strClass($objResult);
         }
     }
     return new static($arrModels, $strTable);
 }
 /**
  * Clear the cache for a given database result and return the number of affected files.
  *
  * @param Result $result The database result.
  *
  * @return int
  */
 private function clearCache($result)
 {
     $delete = array();
     while ($result->next()) {
         $cacheFile = sprintf('system/cache/html/%s/%s.html', substr($result->cacheKey, 0, 1), $result->cacheKey);
         $this->fileSystem->delete($cacheFile);
         $delete[] = $result->id;
     }
     if ($delete) {
         $result = $this->database->execute(Query::removeEntries($delete));
         return $result->affectedRows;
     }
     return 0;
 }
Esempio n. 7
0
 /**
  * Convert a database result to a result array.
  *
  * @param \Database\Result $objRow      The database result.
  *
  * @param string[]         $arrAttrOnly The list of attributes to return, if any.
  *
  * @return array
  */
 protected function convertRowsToResult($objRow, $arrAttrOnly = array())
 {
     $arrResult = array();
     while ($objRow->next()) {
         $arrData = array();
         foreach ($objRow->row() as $strKey => $varValue) {
             if (!$arrAttrOnly || in_array($strKey, $arrAttrOnly)) {
                 $arrData[$strKey] = $this->tryUnserialize($varValue);
             }
         }
         /** @noinspection PhpUndefinedFieldInspection */
         $arrResult[$objRow->id] = $arrData;
     }
     return $arrResult;
 }