Example #1
0
 /**
  * Fetches row(s) by primary key or specified column
  *
  * The argument specifies one or more key value(s).
  * To find multiple rows, the argument must be an array.
  *
  * The find() method returns a ResultSet object
  * if key array is provided or a Row object
  * if a single key value is provided.
  *
  * @param array|string|int  $key    The value(s) of the key
  * @param string|null       $column Column name of the key
  * @return ResultSet|Row Row(s) matching the criteria.
  * @throws \Exception Throw exception if column is not specified
  */
 public function find($key, $column = null)
 {
     $column = $column ?: $this->primaryKeyColumn;
     if (!$column) {
         throw new \Exception('No column is specified.');
     }
     $isScalar = false;
     if (!is_array($key)) {
         $isScalar = true;
         $key = array($key);
     }
     $where = new Where();
     if (count($key) == 1) {
         $where->equalTo($column, $key[0]);
     } else {
         $where->in($column, $key);
     }
     $select = $this->select()->where($where);
     //->limit(1);
     $resultSet = $this->selectWith($select);
     $result = $isScalar ? $resultSet->current() : $resultSet;
     return $result;
 }
Example #2
0
 /**
  * Get root nodes sorted by left value in ASC
  *
  * @param   Where|array  $where
  * @return  Rowset
  */
 public function getRoots($where = null, $order = array())
 {
     if (is_array($where) || $where instanceof Where) {
         $clause = new Where($where);
     } else {
         $clause = new Where();
     }
     $clause->equalTo($this->column['depth'], 0);
     $order = $order ?: array($this->column['left'] . ' ASC');
     $select = $this->select()->where($clause)->order($order);
     return $this->selectWith($select);
 }