Example #1
0
 /**
  * TODO: Complete refractor. This method is ruined with the shared items implemented.
  */
 public function getWhere($where, $order = '', $asc = '', $bindings = array())
 {
     if (!empty($where)) {
         $where = 'WHERE ' . $where;
     }
     if (!empty($order)) {
         $order = 'ORDER BY ' . $order;
         $asc = $asc === true ? 'ASC' : $asc === false ? 'DESC' : '';
     }
     $result = $this->db->query("SELECT *\n            FROM {$this->table}\n            {$where} {$order} {$asc}", ConvertArray::addPrefixToKeys($bindings));
     if (!$result['success']) {
         return $result;
     }
     $resultShared = $this->db->query("SELECT {$this->table}_person.*,\n                {$this->table}_person.id AS share_id,\n                {$this->table}_person.{$this->table}_id AS id,\n                {$this->table}.name AS label_name,\n                CONCAT(person.name, '\\'s ', {$this->table}.name) AS name\n            FROM {$this->table}_person\n                JOIN ({$this->table}\n                    JOIN person\n                    ON {$this->table}.person_id = person.id)\n                ON {$this->table}_id = {$this->table}.id\n            WHERE {$this->table}_person.person_id = {$bindings['person_id']}");
     if (!$resultShared['success']) {
         return $resultShared;
     }
     return array('success' => true, 'data' => array_merge($result['data'], $resultShared['data']));
 }
Example #2
0
 /**
  * @param    int           $id           ID of row to be updated.
  * @param    mixed[]       $bindings     Bindings to be updated.
  *
  * @return   mixed[]                     Promise results with affeced row count.
  *                                       See Database->query().
  */
 public function update($id, $bindings)
 {
     $bindingSetList = ConvertArray::toBindingSetList($bindings);
     $bindings['id'] = $id;
     return $this->db->query("UPDATE {$this->table}\n            SET {$bindingSetList}\n            WHERE id = :id", ConvertArray::addPrefixToKeys($bindings));
 }
Example #3
0
 public function testToQueryLists()
 {
     $lists = ConvertArray::toQueryLists($this->assocArray);
     $this->assertEquals($lists['columns'], 'a, b, c');
     $this->assertEquals($lists['bindings'], ':a, :b, :c');
 }