Example #1
0
 public function getNextJob()
 {
     $query = new Query('\\Octo\\System\\Model\\SystemJob');
     $query->select('*')->from('system_job')->order('run_date', 'ASC')->limit(1);
     if ($query->execute()) {
         $job = $query->fetch();
         if ($job->getRunDate() <= new \DateTime()) {
             return $job;
         }
     }
     return null;
 }
Example #2
0
 /**
  * Get jobs due to be scheduled.
  */
 public function getJobsToSchedule()
 {
     $query = new Query($this->getNamespace('ScheduledJob') . '\\Model\\ScheduledJob', 'read');
     $query->select('s.*');
     $query->from('scheduled_job', 's');
     $query->join('job', 'j', 's.current_job_id = j.id');
     $query->where('(j.id IS NULL) OR ((UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(j.date_updated)) >= s.frequency AND j.status > 1)');
     try {
         $query->execute();
         return new ScheduledJobCollection($query->fetchAll());
     } catch (PDOException $ex) {
         throw new StoreException('Could not get ScheduledJob by CurrentJob', 0, $ex);
     }
 }
Example #3
0
 public function getLastEntry($scope)
 {
     $query = new Query($this->getNamespace('Log') . '\\Model\\Log', 'read');
     $query->select('*')->from('log')->limit(1);
     $query->where('scope = :scope');
     $query->bind(':scope', $scope);
     $query->order('id', 'DESC');
     try {
         $query->execute();
         return $query->fetch();
     } catch (PDOException $ex) {
         throw new StoreException('Could not get Log by Id', 0, $ex);
     }
 }
Example #4
0
 /**
  * @param $value
  * @param string $useConnection Connection type to use.
  * @throws StoreException
  * @return Contact
  */
 public function getByEmail($value, $useConnection = 'read')
 {
     if (is_null($value)) {
         throw new StoreException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
     }
     $query = new Query($this->getNamespace('Contact') . '\\Model\\Contact', $useConnection);
     $query->select('*')->from('contact')->limit(1);
     $query->where('`email` = :email');
     $query->bind(':email', $value);
     try {
         $query->execute();
         $result = $query->fetch();
         $this->setCache($value, $result);
         return $result;
     } catch (PDOException $ex) {
         throw new StoreException('Could not get Contact by Email', 0, $ex);
     }
 }
 /**
  * @param $value
  * @param string $useConnection Connection type to use.
  * @throws StoreException
  * @return ContentItem
  */
 public function getById($value, $useConnection = 'read')
 {
     if (is_null($value)) {
         throw new StoreException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
     }
     // This is the primary key, so try and get from cache:
     $cacheResult = $this->getFromCache($value);
     if (!empty($cacheResult)) {
         return $cacheResult;
     }
     $query = new Query($this->getNamespace('ContentItem') . '\\Model\\ContentItem', $useConnection);
     $query->select('*')->from('content_item')->limit(1);
     $query->where('`id` = :id');
     $query->bind(':id', $value);
     try {
         $query->execute();
         $result = $query->fetch();
         $this->setCache($value, $result);
         return $result;
     } catch (PDOException $ex) {
         throw new StoreException('Could not get ContentItem by Id', 0, $ex);
     }
 }
Example #6
0
 public function getList()
 {
     $query = new Database\Query('\\Octo\\System\\Model\\Contact', 'read');
     $query->select('*')->from('contact')->order('first_name', 'ASC')->order('last_name', 'ASC')->execute();
     return new Octo\System\Model\ContactCollection($query->fetchAll());
 }
Example #7
0
 /**
  * @param $value
  * @param array $options Limits, offsets, etc.
  * @param string $useConnection Connection type to use.
  * @throws StoreException
  * @return SystemJob[]
  */
 public function getByRunDate($value, $options = [], $useConnection = 'read')
 {
     if (is_null($value)) {
         throw new StoreException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
     }
     $query = new Query($this->getNamespace('SystemJob') . '\\Model\\SystemJob', $useConnection);
     $query->from('system_job')->where('`run_date` = :run_date');
     $query->bind(':run_date', $value);
     $this->handleQueryOptions($query, $options);
     try {
         $query->execute();
         return $query->fetchAll();
     } catch (PDOException $ex) {
         throw new StoreException('Could not get SystemJob by RunDate', 0, $ex);
     }
 }
Example #8
0
 /**
  * @param $value
  * @param array $options Limits, offsets, etc.
  * @param string $useConnection Connection type to use.
  * @throws StoreException
  * @return PermissionCollection
  */
 public function getByUserId($value, $options = [], $useConnection = 'read')
 {
     if (is_null($value)) {
         throw new StoreException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
     }
     $query = new Query($this->getNamespace('Permission') . '\\Model\\Permission', $useConnection);
     $query->from('permission')->where('`user_id` = :user_id');
     $query->bind(':user_id', $value);
     $this->handleQueryOptions($query, $options);
     try {
         $query->execute();
         return new PermissionCollection($query->fetchAll());
     } catch (PDOException $ex) {
         throw new StoreException('Could not get Permission by UserId', 0, $ex);
     }
 }
Example #9
0
 /**
  * @param $page
  * @param $perPage
  * @param array $order
  * @param array $criteria
  * @param array $bind
  * @return Database\Query
  */
 public function query($page, $perPage, array $order = [], array $criteria = [], array $bind = [])
 {
     $query = new Database\Query($this->modelName, 'read');
     $query->select($this->tableName . '.*')->from($this->tableName);
     $page -= 1;
     // Make the pagination zero-indexed
     $offset = $page * $perPage;
     $query->offset($offset);
     $query->limit($perPage);
     // Handle WHERE criteria:
     if (count($criteria)) {
         $criteriaContainer = new Database\Query\Criteria();
         foreach ($criteria as $where) {
             if ($where instanceof Database\Query\Criteria) {
                 $criteriaContainer->add($where);
             } else {
                 $thisCriteria = new Database\Query\Criteria();
                 $thisCriteria->where($where);
                 $criteriaContainer->add($thisCriteria);
             }
         }
         $query->where($criteriaContainer);
     }
     // Handle ORDER BY:
     if (count($order)) {
         $query->order($order[0], $order[1]);
     }
     // Handle bound parameters:
     if (count($bind)) {
         $query->bindAll($bind);
     }
     return $query;
 }
Example #10
0
 /**
  * @param $value
  * @param array $options Limits, offsets, etc.
  * @param string $useConnection Connection type to use.
  * @throws StoreException
  * @return SettingCollection
  */
 public function getByScope($value, $options = [], $useConnection = 'read')
 {
     if (is_null($value)) {
         throw new StoreException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
     }
     $query = new Query($this->getNamespace('Setting') . '\\Model\\Setting', $useConnection);
     $query->from('setting')->where('`scope` = :scope');
     $query->bind(':scope', $value);
     $this->handleQueryOptions($query, $options);
     try {
         $query->execute();
         return new SettingCollection($query->fetchAll());
     } catch (PDOException $ex) {
         throw new StoreException('Could not get Setting by Scope', 0, $ex);
     }
 }
Example #11
0
 /**
  * @param Query $query
  * @param array $options
  */
 public function handleQueryOptions(Query &$query, array $options)
 {
     if (array_key_exists('limit', $options)) {
         $query->limit($options['limit']);
     }
     if (array_key_exists('offset', $options)) {
         $query->offset($options['offset']);
     }
     if (array_key_exists('order', $options)) {
         if (is_string($options['order'])) {
             $options['order'] = array($options['order']);
         }
         foreach ($options['order'] as $order) {
             $query->order($order[0], $order[1]);
         }
     }
 }
 /**
  * @param $value
  * @param array $options Limits, offsets, etc.
  * @param string $useConnection Connection type to use.
  * @throws StoreException
  * @return ScheduledJobCollection
  */
 public function getByCurrentJobId($value, $options = [], $useConnection = 'read')
 {
     if (is_null($value)) {
         throw new StoreException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
     }
     $query = new Query($this->getNamespace('ScheduledJob') . '\\Model\\ScheduledJob', $useConnection);
     $query->from('scheduled_job')->where('`current_job_id` = :current_job_id');
     $query->bind(':current_job_id', $value);
     $this->handleQueryOptions($query, $options);
     try {
         $query->execute();
         return new ScheduledJobCollection($query->fetchAll());
     } catch (PDOException $ex) {
         throw new StoreException('Could not get ScheduledJob by CurrentJobId', 0, $ex);
     }
 }