Ejemplo n.º 1
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);
     }
 }
Ejemplo n.º 2
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);
     }
 }
Ejemplo n.º 3
0
 /**
  * @param $value
  * @param string $useConnection Connection type to use.
  * @throws StoreException
  * @return SystemJob
  */
 public function getById($value, $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->select('*')->from('system_job')->limit(1);
     $query->where('`id` = :id');
     $query->bind(':id', $value);
     try {
         $query->execute();
         return $query->fetch();
     } catch (PDOException $ex) {
         throw new StoreException('Could not get SystemJob by Id', 0, $ex);
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 5
0
 /**
  * @param $value
  * @param string $useConnection Connection type to use.
  * @throws StoreException
  * @return Permission
  */
 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('Permission') . '\\Model\\Permission', $useConnection);
     $query->select('*')->from('permission')->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 Permission by Id', 0, $ex);
     }
 }
Ejemplo n.º 6
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;
 }