Ejemplo n.º 1
0
 /**
  * Get service
  *
  * @return string|boolean
  */
 public function getService()
 {
     $select = $this->select();
     $select->from('application_delete_content_service')->columns(['id', 'path'])->limit(1)->order('processed asc')->order('id asc');
     $statement = $this->prepareStatementForSqlObject($select);
     $resultSet = new ResultSet();
     $resultSet->initialize($statement->execute());
     if (!empty($resultSet->current())) {
         if (true === ($result = $this->markServiceProcessed($resultSet->current()['id']))) {
             return $resultSet->current()['path'];
         }
     }
     return false;
 }
 /**
  * Get comments count
  *
  * @param boolean $allowApprove
  * @param integer $pageId
  * @param string $pageSlug
  * @param integer $lastRightKey
  * @return integer
  */
 public function getCommentsCount($allowApprove, $pageId, $pageSlug = null, $lastRightKey = null)
 {
     $select = $this->select();
     $select->from('comment_list')->columns(['comments_count' => new Expression('COUNT(*)')])->where(['page_id' => $pageId, 'slug' => $pageSlug]);
     if (!$allowApprove) {
         $select->where(['hidden' => CommentNestedSet::COMMENT_STATUS_NOT_HIDDEN]);
     }
     if ($lastRightKey) {
         $select->where->lessThan($this->getCommentModel()->getRightKey(), $lastRightKey);
     }
     $statement = $this->prepareStatementForSqlObject($select);
     $resultSet = new ResultSet();
     $resultSet->initialize($statement->execute());
     return !empty($resultSet->current()->comments_count) ? $resultSet->current()->comments_count : 0;
 }
 public function testCallingBufferAfterIterationThrowsException()
 {
     $this->resultSet->initialize($this->getMock('Zend\\Db\\Adapter\\Driver\\ResultInterface'));
     $this->resultSet->current();
     $this->setExpectedException('Zend\\Db\\ResultSet\\Exception\\RuntimeException', 'Buffering must be enabled before iteration is started');
     $this->resultSet->buffer();
 }
Ejemplo n.º 4
0
 /**
  * Check activation code
  *
  * @param integer $userId
  * @param string $activationCode
  * @return boolean
  */
 public function checkActivationCode($userId, $activationCode)
 {
     $select = $this->select();
     $select->from('user_list')->columns(['user_id'])->where(['user_id' => $userId, 'activation_code' => $activationCode]);
     $statement = $this->prepareStatementForSqlObject($select);
     $resultSet = new ResultSet();
     $resultSet->initialize($statement->execute());
     return $resultSet->current() ? true : false;
 }
Ejemplo n.º 5
0
 /**
  * Is answer vote exist
  *
  * @param integer $questionId
  * @return boolean
  */
 public function isAnswerVoteExist($questionId)
 {
     $remote = new RemoteAddress();
     $remote->setUseProxy(true);
     $select = $this->select();
     $select->from('poll_answer_track')->columns(['id'])->where(['question_id' => $questionId, 'ip' => inet_pton($remote->getIpAddress())]);
     $statement = $this->prepareStatementForSqlObject($select);
     $resultSet = new ResultSet();
     $resultSet->initialize($statement->execute());
     return !empty($resultSet->current());
 }
Ejemplo n.º 6
0
 /**
  * Is question free
  *
  * @param string $question
  * @param integer $questionId
  * @return boolean
  */
 public function isQuestionFree($question, $questionId = 0)
 {
     $select = $this->select();
     $select->from('poll_question')->columns(['id'])->where(['question' => $question, 'language' => $this->getCurrentLanguage()]);
     if ($questionId) {
         $select->where([new NotInPredicate('id', [$questionId])]);
     }
     $statement = $this->prepareStatementForSqlObject($select);
     $resultSet = new ResultSet();
     $resultSet->initialize($statement->execute());
     return $resultSet->current() ? false : true;
 }
Ejemplo n.º 7
0
 /**
  * Is a role's name free
  *
  * @param string $roleName
  * @param integer $roleId
  * @return boolean
  */
 public function isRoleNameFree($roleName, $roleId = 0)
 {
     $select = $this->select();
     $select->from('acl_role')->columns(['id'])->where(['name' => $roleName]);
     if ($roleId) {
         $select->where([new NotInPredicate('id', [$roleId])]);
     }
     $statement = $this->prepareStatementForSqlObject($select);
     $resultSet = new ResultSet();
     $resultSet->initialize($statement->execute());
     return $resultSet->current() ? false : true;
 }
 /**
  * Get joined product
  * 
  * @param int $id product id
  * @return ProductJoinedRow
  * @throws Exception\InvalidArgumentException
  */
 public function getProductJoinedRow($id)
 {
     $id = (int) $id;
     $pt = $this->getJoinedTable('ProductTable')->getTable();
     $pdt = $this->getJoinedTable('ProductDescriptionTable')->getTable();
     $select = $this->sql->select()->from("{$pt}")->columns(array("*"))->join($pdt, "{$pt}.product_id = {$pdt}.product_id", array('description_id', 'description'), Select::JOIN_LEFT)->order("{$pt}.product_id DESC")->where("{$pt}.product_id = {$id}");
     $statement = $this->sql->prepareStatementForSqlObject($select);
     $resultSet = new ResultSet(ResultSet::TYPE_ARRAYOBJECT, new ProductJoinedRow());
     $resultSet->initialize($statement->execute());
     if (!$resultSet->count()) {
         throw new Exception\InvalidArgumentException("Not found joined product: {$id}");
     }
     return $resultSet->current();
 }
Ejemplo n.º 9
0
 /**
  * Iterator: get current item
  *
  * @throws Exception\LogicException whenever a record cannot be instanciated, due to missing column specs
  * @return Record
  */
 public function current()
 {
     $data = $this->dataSource->current();
     if (!$this->has_complete_record_definition) {
         $data_columns = array_keys($this->table->getColumnsInformation());
         $record_columns = array_keys((array) $data);
         $matches = array_intersect($data_columns, $record_columns);
         if (count($matches) != count($data_columns)) {
             $missings = join(',', array_diff($data_columns, $record_columns));
             $msg = __METHOD__ . ": Cannot create a Record due to incomplete or aliased column definition (missing: {$missings}).";
             $msg .= "Check whether columns have been modified in TableSearch::columns() method, or use an toArray(), toJson()... version of the ResultSet.";
             throw new Exception\LogicException($msg);
         }
         $this->has_complete_record_definition = true;
     }
     $record = $this->table->record($data, $ignore = true);
     $record->setState(Record::STATE_CLEAN);
     return $record;
 }
Ejemplo n.º 10
0
 public function get_last_periodic_transaction(Item $item, $features)
 {
     $sql = $this->tableGateway->getSql();
     $select = $this->tableGateway->getSql()->select();
     $select->where($features);
     $select->order('accured_time DESC');
     $statement = $sql->prepareStatementForSqlObject($select);
     $results = $statement->execute();
     $rowset = new ResultSet();
     $rowset->initialize($results);
     $row = $rowset->current();
     if (!$row) {
         //			throw new \Exception("Could not find row $id");
     }
     return $row;
     //		$row = array();
     //		if (!empty($rowset))
     //			$row = $rowset[sizeof($rowset)-1];
     //		return $row;
 }
Ejemplo n.º 11
0
 public function isValid($username, $password)
 {
     $sql = $this->getObjDbSql();
     $select = $sql->select();
     $select->columns(array('u_kode', 'u_nama', 'u_kode_fungsional', 'u_gelar_diplomatik', 'u_urutan', 'u_password'));
     $select->from($this->table);
     $select->where(array("u_status=1", "u_nama = '{$username}' "));
     $statement = $sql->prepareStatementForSqlObject($select);
     $result = $statement->execute();
     $resultSet = new ResultSet();
     $resultSet->initialize($result);
     //return $resultSet->toArray();
     $user = $resultSet->current();
     if (!$user) {
         return false;
     }
     //
     if (md5($password) == $user['u_password']) {
         return $user;
     } else {
         return false;
     }
 }
 /**
  * Is a category free
  *
  * @param string $categoryName
  * @param integer $categoryId
  * @return boolean
  */
 public function isCategoryFree($categoryName, $categoryId = 0)
 {
     $select = $this->select();
     $select->from('miniphotogallery_category')->columns(['id'])->where(['name' => $categoryName, 'language' => $this->getCurrentLanguage()]);
     if ($categoryId) {
         $select->where([new NotInPredicate('id', [$categoryId])]);
     }
     $statement = $this->prepareStatementForSqlObject($select);
     $resultSet = new ResultSet();
     $resultSet->initialize($statement->execute());
     return $resultSet->current() ? false : true;
 }
 /**
  * Get one row of table for given $query
  *
  * @param \Zend\Db\Sql\Select $query
  * @param
  *            string | $prototypeClass
  * @return mixed
  */
 public function fetchRow(\Zend\Db\Sql\Select $query = null, $prototypeClass = null)
 {
     if (!$query) {
         $query = $this->getBaseQuery()->limit(1);
     }
     $stmt = $this->getSql()->prepareStatementForSqlObject($query);
     $res = $stmt->execute();
     $resultSet = new ResultSet();
     $arrayObjectPrototypeClass = $prototypeClass ? $prototypeClass : $this->arrayObjectPrototypeClass;
     $resultSet->setArrayObjectPrototype(new $arrayObjectPrototypeClass());
     $resultSet->initialize($res);
     return $resultSet->current();
 }
 /**
  * Check an item in shopping cart
  *
  * @param integer $objectId
  * @param integer $module
  * @return integer
  */
 public function inShoppingCart($objectId, $module)
 {
     $select = $this->select();
     $select->from('payment_shopping_cart')->columns(['id'])->where(['object_id' => $objectId, 'module' => $module, 'shopping_cart_id' => $this->getShoppingCartId(), 'language' => $this->getCurrentLanguage()]);
     $statement = $this->prepareStatementForSqlObject($select);
     $resultSet = new ResultSet();
     $resultSet->initialize($statement->execute());
     return $resultSet->current() ? $resultSet->current()->id : null;
 }
Ejemplo n.º 15
0
 /**
  * Is page already rated
  *
  * @param integer $pageId
  * @param string $slug
  * @return boolean
  */
 public function isPageRated($pageId, $slug = null)
 {
     $remote = new RemoteAddress();
     $remote->setUseProxy(true);
     $visitorIp = inet_pton($remote->getIpAddress());
     $select = $this->select();
     $select->from(['a' => 'page_rating'])->columns(['id'])->join(['b' => 'page_rating_track'], new Expression('a.id = b.rating_id and b.ip = ?', [$visitorIp]), ['track_id' => 'id'], 'left')->where(['page_id' => $pageId, 'slug' => $slug]);
     $statement = $this->prepareStatementForSqlObject($select);
     $resultSet = new ResultSet();
     $resultSet->initialize($statement->execute());
     $data = $resultSet->current();
     if ($data && $data['track_id']) {
         return true;
     }
     return false;
 }
 protected function _createSessionFromResult(Db\ResultSet\ResultSet $result)
 {
     if (!$result->count()) {
         return NULL;
     }
     return $this->_arrayToSession((array) $result->current());
 }
Ejemplo n.º 17
0
 /**
  * Get module info
  *
  * @param string $moduleName
  * @return array
  */
 public function getModuleInfo($moduleName)
 {
     // generate cache name
     $cacheName = CacheUtility::getCacheName(self::CACHE_MODULE_BY_NAME . $moduleName);
     // check data in cache
     if (null === ($module = $this->staticCacheInstance->getItem($cacheName))) {
         $select = $this->select();
         $select->from('application_module')->columns(['id', 'name', 'type', 'status', 'version', 'vendor', 'vendor_email', 'description', 'layout_path'])->where(['name' => $moduleName]);
         $statement = $this->prepareStatementForSqlObject($select);
         $resultSet = new ResultSet();
         $resultSet->initialize($statement->execute());
         if (null != ($module = $resultSet->current())) {
             // save data in cache
             $this->staticCacheInstance->setItem($cacheName, $module);
             $this->staticCacheInstance->setTags($cacheName, [self::CACHE_MODULES_DATA_TAG]);
         }
     }
     return $module;
 }
Ejemplo n.º 18
0
 /**
  * Generate page slug
  *
  * @param integer $pageId
  * @param string $title
  * @param string $spaceDevider
  * @return string
  */
 public function generatePageSlug($pageId, $title, $spaceDevider = '-')
 {
     // generate a slug
     $newSlug = $slug = SlugUtility::slugify($title, self::PAGE_SLUG_LENGTH, $spaceDevider);
     $slagSalt = null;
     while (true) {
         // check the slug existent in structure pages
         $select = $this->select();
         $select->from('page_structure')->columns(['slug'])->where(['slug' => $newSlug, 'language' => $this->getCurrentLanguage()]);
         $select->where([new NotInPredicate('id', [$pageId])]);
         $statement = $this->prepareStatementForSqlObject($select);
         $structurePagesResultSet = new ResultSet();
         $structurePagesResultSet->initialize($statement->execute());
         // check the slug existent in system pages
         $select = $this->select();
         $select->from('page_system')->columns(['slug'])->where(['slug' => $newSlug]);
         $statement = $this->prepareStatementForSqlObject($select);
         $systemPagesResultSet = new ResultSet();
         $systemPagesResultSet->initialize($statement->execute());
         // generated slug not found
         if (!$structurePagesResultSet->current() && !$systemPagesResultSet->current()) {
             break;
         }
         $newSlug = $pageId . $spaceDevider . $slug . $slagSalt;
         // add an extra slug
         $slagSalt = $spaceDevider . SlugUtility::generateRandomSlug($this->slugLength);
         // add a slug
     }
     return $newSlug;
 }
Ejemplo n.º 19
0
 /**
  * Get user info
  *
  * @param integer|string $userId
  * @param string $field
  * @return array
  */
 public function getUserInfo($userId, $field = self::USER_INFO_BY_ID)
 {
     // check data in a memory
     if (isset(self::$userInfo[$userId][$field])) {
         return self::$userInfo[$userId][$field];
     }
     // process a field name
     $field = in_array($field, $this->userInfoFields) ? $field : self::USER_INFO_BY_ID;
     // generate a cache name
     $cacheName = CacheUtility::getCacheName(self::CACHE_USER_INFO . $userId, [$field]);
     // check data in cache
     if (null === ($userInfo = $this->staticCacheInstance->getItem($cacheName))) {
         $select = $this->select();
         $select->from(['a' => 'user_list'])->columns(['user_id', 'nick_name', 'slug', 'status', 'email', 'phone', 'first_name', 'last_name', 'address', 'role', 'language', 'time_zone', 'layout', 'api_key', 'api_secret', 'registered', 'activation_code', 'avatar'])->join(['b' => 'acl_role'], 'a.role = b.id', ['role_name' => 'name'], 'left')->join(['c' => 'application_time_zone'], 'a.time_zone = c.id', ['time_zone_name' => 'name'], 'left')->where([$field => $userId]);
         $statement = $this->prepareStatementForSqlObject($select);
         $resultSet = new ResultSet();
         $resultSet->initialize($statement->execute());
         $userInfo = $resultSet->current() ? (array) $resultSet->current() : [];
         // save data in cache
         if ($userInfo) {
             $this->staticCacheInstance->setItem($cacheName, $userInfo);
             $this->staticCacheInstance->setTags($cacheName, [self::CACHE_USER_DATA_TAG, self::CACHE_USER_SPECIFIC_DATA_TAG . $userInfo['user_id']]);
         }
     }
     self::$userInfo[$userId][$field] = $userInfo;
     return $userInfo;
 }
 /**
  * Iterator: get current item
  *
  * @return array
  */
 public function current()
 {
     return $this->zfResultSet->current();
 }
Ejemplo n.º 21
0
 /**
  * Is the currency code free
  *
  * @param string $code
  * @param integer $currencyCodeId
  * @return boolean
  */
 public function isCurrencyCodeFree($code, $currencyCodeId = 0)
 {
     $select = $this->select();
     $select->from('payment_currency')->columns(['id'])->where(['code' => $code]);
     if ($currencyCodeId) {
         $select->where([new NotInPredicate('id', [$currencyCodeId])]);
     }
     $statement = $this->prepareStatementForSqlObject($select);
     $resultSet = new ResultSet();
     $resultSet->initialize($statement->execute());
     return $resultSet->current() ? false : true;
 }
 /**
  * Is slug free
  *
  * @param string $slug
  * @param integer $newsId
  * @return boolean
  */
 public function isSlugFree($slug, $newsId = 0)
 {
     $select = $this->select();
     $select->from('news_list')->columns(['id'])->where(['slug' => $slug, 'language' => $this->getCurrentLanguage()]);
     if ($newsId) {
         $select->where([new NotInPredicate('id', [$newsId])]);
     }
     $statement = $this->prepareStatementForSqlObject($select);
     $resultSet = new ResultSet();
     $resultSet->initialize($statement->execute());
     return $resultSet->current() ? false : true;
 }
Ejemplo n.º 23
0
 /**
  * Generate slug
  *
  * @param integer $objectId
  * @param string $title
  * @param string $table
  * @param string $idField
  * @param integer $slugLength
  * @param array $filters
  * @param string $slugField
  * @param string $spaceDivider
  * @return string
  */
 public function generateSlug($objectId, $title, $table, $idField, $slugLength = 60, array $filters = [], $slugField = 'slug', $spaceDivider = '-')
 {
     // generate a slug
     $newSlug = $slug = SlugUtility::slugify($title, $slugLength, $spaceDivider);
     $slagSalt = null;
     while (true) {
         // check the slug existent
         $select = $this->select();
         $select->from($table)->columns([$slugField])->where([$slugField => $newSlug, 'language' => $this->getCurrentLanguage()] + $filters);
         $select->where([new NotInPredicate($idField, [$objectId])]);
         $statement = $this->prepareStatementForSqlObject($select);
         $resultSet = new ResultSet();
         $resultSet->initialize($statement->execute());
         // generated slug not found
         if (!$resultSet->current()) {
             break;
         } else {
             $newSlug = $objectId . $spaceDivider . $slug . $slagSalt;
         }
         // add an extra slug
         $slagSalt = $spaceDivider . SlugUtility::generateRandomSlug($this->slugLength);
         // add a salt
     }
     return $newSlug;
 }