/** * Delete the tags for the given object * * @param object $item */ public function deleteTags($item) { $type = mb_strtolower(get_class($item)); $id = (int) $item->id; // okay, delete ahoy $this->dbService->delete('tag', 'itemtype=' . $this->dbService->quote($type) . ' and itemid=' . $id); }
/** * Generates the appropriate query for returning a list of issues * * @param array $where * @return arrayobject */ protected function getList($type, $where = array()) { $query = $this->_getParam('query'); if (mb_strlen($query) >= 2) { $where[] = new Zend_Db_Expr("title like " . $this->dbService->quote('%' . $query . '%') . " OR description like " . $this->dbService->quote('%' . $query . '%')); } // Handle this up here otherwise a model object might take $sortDir = $this->_getParam('sortorder', $this->_getParam('dir', 'desc')); if ($sortDir == 'up' || $sortDir == 'asc') { $sortDir = 'asc'; } else { $sortDir = 'desc'; } // now just iterate parameters $params = $this->_getAllParams(); unset($params['title']); unset($params['sortorder']); $dummyObj = new $type(); // get all the type's parameters $fields = $dummyObj->unBind(); foreach ($fields as $name => $val) { // if we have a param with $name, add it to the filter $val = ifset($params, $name, null); if (!is_null($val)) { $where[$name . ' ='] = $val; } } // If not a User, can only see non-private issues if (za()->getUser()->getRole() == User::ROLE_EXTERNAL) { if (isset($fields['isprivate'])) { $where['isprivate='] = 0; } if (isset($fields['clientid'])) { $client = $this->clientService->getUserClient(za()->getUser()); $where['clientid='] = $client->id; } } $sort = $this->_getParam('sortname', $this->_getParam('sort', 'updated')); $sort .= ' ' . $sortDir; $this->view->totalCount = $this->dbService->getObjectCount($where, $type); $currentPage = ifset($params, 'page', 1); $this->view->listSize = $this->_getParam('rp', za()->getConfig('project_list_size', 10)); if ($this->_getParam("unlimited")) { $currentPage = null; } return $this->dbService->getObjects($type, $where, $sort, $currentPage, $this->view->listSize); }
/** * Get all items that are the pointy end of a linking tree. These items * exist in a 'from' relationship, but NOT as a 'to' target of a link. * @return ArrayObject */ public function getOrphanItems($type, $where = array(), $sortby = 'id asc') { /* @var $select Zend_Db_Select */ $select = $this->dbService->select(); $tableName = mb_strtolower($this->sanitizeType($type)); // $tableName = $this->dbService->quote(mb_strtolower($type)); // select * from $type left join itemlink on itemlink.type = $type and itemlink.to=$type.id where itemlink.to is null $select->from($tableName)->joinLeft('itemlink', 'itemlink.totype = ' . $this->dbService->quote($type) . ' and itemlink.toid=' . $tableName . '.id', 'itemlink.toid')->where(new Zend_Db_Expr('itemlink.toid is null ')); foreach ($where as $field => $value) { if ($value instanceof Zend_Db_Expr && is_int($field)) { $select->where($value); } else { $select->where($field . ' ?', $value); } } $select->order($sortby); $objects = $this->dbService->fetchObjects($type, $select); return $objects; }
public function getContactsByNames($names) { $select = $this->dbService->select(); /* @var $select Zend_Db_Select */ $select->from('contact'); $where = ''; $sep = ''; foreach ($names as $name) { if (mb_strlen($name) < 3) { continue; } $select->orWhere("firstname like " . $this->dbService->quote($name . '%')); $select->orWhere("lastname like " . $this->dbService->quote($name . '%')); /* $where .= $sep . ' firstname like '.$this->dbService->quote($name.'%'); $sep = ' OR '; $where .= $sep . ' lastname like '.$this->dbService->quote($name.'%');*/ } $contacts = $this->dbService->fetchObjects('Contact', $select); $select->order("firstname asc"); return $contacts; }
/** * Remove a watch * * @param CrmUser $user * @param int $id * @param string $type */ public function removeWatch($user, $id, $type) { // just delete direct, no need to get the // object first... $this->dbService->delete('itemwatch', "userid=" . $this->dbService->quote($user->username) . " AND itemid={$id} AND itemtype='{$type}'"); }