public static function getUsers() { $userModel = new self(); $select = $userModel->select(); $select->order(array('last_name', 'first_name')); return $userModel->fetchAll($select); }
/** * Все таблицы для хранения данных имеют префикс * */ protected function _setup() { parent::_setup(); $this->_cleanName = $this->_name; $this->_name = self::PREFIX_TABLE . $this->_name; if (false == array_key_exists($this->_cleanName, self::$setupedTables)) { $modelFields = new Modules_Publications_Model_Fields(); $this->_tableProfile = $modelFields->fetchAllByTableName($this->_cleanName); foreach ($this->_tableProfile as $row) { if ($row->list_values) { if (false == array_key_exists($row->list_values, self::$linkedData)) { if ('routes' == $row->list_values) { self::$linkedData[$row->list_values] = Modules_Router_Model_Router::getInstance()->getRoutesTreeHash(); } else { $model = new self($row->list_values); self::$linkedData[$row->list_values] = $model->fetchAll()->toArray(); } } self::$linkedFieldsTableData[$this->_cleanName . '_' . $row->name] = self::$linkedData[$row->list_values]; } } self::$setupedTables[$this->_cleanName] = $this->_tableProfile; } else { $this->_tableProfile = self::$setupedTables[$this->_cleanName]; } }
public static function getTypes() { $Type = new self(); $Types = $Type->fetchAll(null, "Type"); if ($Types) { return $Types->toArray(); } else { return array(); } }
/** * Returns the topics table as a domain model. * STAGE 3: Choose, create, and optionally update models using business logic. * The domain model can be manipulated later by controllers. * @return array of topic row set objects indexed by topic id */ public static function getDomainModel() { if (self::$_domainModel === null) { $topicsTable = new self(); $rowset = $topicsTable->fetchAll(1, 'modification_time'); foreach ($rowset as $row) { self::$_domainModel[$row->topic_id] = $row; } } return self::$_domainModel; }
/** * * get multi Options country for google map */ public static function getMapMultiOptions() { $t = new self(); $select = $t->select()->where('status= 1')->order('name'); $result = array(); $result[''] = ''; foreach ($t->fetchAll($select) as $item) { $result[$item->name] = $item->name; } return $result; }
public static function getPageAlbums($IDPage) { $Ret = array(); $A = new self(); $Albums = $A->fetchAll("IDParent = '{$IDPage}' AND Extension IS NULL", 'Title'); if ($Albums) { foreach ($Albums as $Album) { $A = new self(); $Ret[] = $A->copyFromDb($Album); } } return $Ret; }
public static function fetchAllRecords($quiz_id) { $self = new self(); $constraints = array(array("mode" => "AND", "key" => "quiz_id", "value" => $quiz_id, "method" => "=")); $objs = $self->fetchAll($constraints, "=", "AND", $self->default_sort_column, $sort_order); $output = array(); if (!empty($objs)) { foreach ($objs as $o) { $output[] = $o; } } return $output; }
public static function fetchAllRecords($qquestion_id, $response_active = 1) { $self = new self(); $constraints = array(array("mode" => "AND", "key" => "qquestion_id", "value" => $qquestion_id, "method" => "="), array("mode" => "AND", "key" => "response_active", "value" => $response_active, "method" => "=")); $objs = $self->fetchAll($constraints, "=", "AND", $sort_col, $sort_order); $output = array(); if (!empty($objs)) { foreach ($objs as $o) { $output[] = $o; } } return $output; }
public static function getNew($IDParent, $lastID) { $TheChat = new self(); $Messages = $TheChat->fetchAll("IDParent = '{$IDParent}' AND IDChat > {$lastID} AND Date + INTERVAL 20 MINUTE > NOW()", "Date"); $Ret = array(); if ($Messages) { foreach ($Messages as $Message) { $TheChat = new self(); $Ret[] = $TheChat->copyFromDb($Message); } } return $Ret; }
public static function getPhotosByAlbum($IDAlbum) { $ThePhoto = new self(); $Photos = $ThePhoto->fetchAll("IDParent = '{$IDAlbum}' AND Extension IS NOT NULL"); $Ret = array(); if ($Photos) { foreach ($Photos as $Photo) { $ThePhoto = new self(); $Ret[] = $ThePhoto->copyFromDb($Photo); } } return $Ret; }
public static function fetchAllRecords($status = "open") { $self = new self(); $constraints = array(array("mode" => "AND", "key" => "status", "value" => $status, "method" => "=")); $objs = $self->fetchAll($constraints, "=", "AND", $sort_col, $sort_order); $output = array(); if (!empty($objs)) { foreach ($objs as $o) { $output[] = $o; } } return $output; }
public static function fetchAllByDraftID($draft_id = 0) { $self = new self(); $constraints = array(array("mode" => "AND", "key" => "draft_id", "value" => $draft_id, "method" => "=")); $objs = $self->fetchAll($constraints, "=", "AND", $sort_col, $sort_order); $output = array(); if (!empty($objs)) { foreach ($objs as $o) { $output[] = $o; } } return $output; }
public static function getConversation($IDMessage) { $TheMessage = new self(); $Select = $TheMessage->select()->join(array('mm' => 'message'), 'message.IDParent = mm.IDParent', array())->where("mm.IDMessage = '{$IDMessage}'")->order("mm.Date"); $Messages = $TheMessage->fetchAll($Select); $Ret = array(); if ($Messages) { foreach ($Messages as $Message) { $TheMessage = new self(); $Ret[] = $TheMessage->copyFromDb($Message); } } return $Ret; }
public function getPosts($Start = 0, $Limit = self::POSTS_LIMIT) { $TheForum = new self(); $Posts = $TheForum->fetchAll("IDParent = '" . $this->IDForum . "' AND IsForum = '0'", "DateLastModify", $Limit, $Start); $Ret = array(); if ($Posts) { foreach ($Posts as $Post) { $TheForum = new Zwe_Forum_Message_Post(); $TheForum->copyFromDb($Post); $Ret[] = $TheForum; } } return $Ret; }
public function getComments($Start = 0, $Limit = self::COMMENTS_LIMIT) { $TheForum = new self(); $Comments = $TheForum->fetchAll("IDParent = '" . $this->IDForum . "'", "Date", $Limit, $Start); $Ret = array(); if ($Comments) { foreach ($Comments as $Comment) { $TheForum = new Zwe_Forum_Message_Comment(); $TheForum->copyFromDb($Comment); $Ret[] = $TheForum; } } return $Ret; }
/** * Ritorna le news di una determinata pagina. * Se non sono presenti ritorna un array vuoto. * * @static * @param int $IDPage L'identificativo della pagina di cui si vogliono estrarre le news * @param int $Count * @param int $Offset * * @return array */ public static function getPageNews($IDPage, $Count = null, $Offset = null) { $Ret = array(); $N = new self(); $News = $N->fetchAll("IDPage = '{$IDPage}' AND IsComment = '0'", 'Date DESC', $Count, $Offset); if ($News) { foreach ($News as $New) { $N = new self(); $N->copyFromDb($New); $N->Author = Zwe_Model_User::getUserById($N->IDAuthor); $Ret[] = $N; } } return $Ret; }
public static function getUsersOnline($Age = 1) { $TheOnline = new self(); $Onlines = $TheOnline->fetchAll("Date + INTERVAL {$Age} MINUTE > NOW()", "IDLocation"); $Ret = array(); foreach ($Onlines as $Online) { $TheOnline = new self(); $TheOnline->copyFromDb($Online); $TheOnline->User = App_Model_User::getUserById($Online->IDUser); if ($TheOnline->IDLocation) { $TheOnline->Location = Mappa_Model_Luogo::get($Online->IDLocation); } $Ret[] = $TheOnline; } return $Ret; }
public static function fetchAllRecords($group_id = NULL, $course_id = NULL, $active = 1) { $self = new self(); $constraints = array(array("mode" => "AND", "key" => "active", "value" => $active, "method" => "=")); if (!is_null($group_id)) { $constraints[] = array("mode" => "AND", "key" => "cohort", "value" => $group_id, "method" => "="); } if (!is_null($course_id)) { $constraints[] = array("mode" => "AND", "key" => "course_id", "value" => $course_id, "method" => "="); } $objs = $self->fetchAll($constraints, "=", "AND", $sort_col, $sort_order); $output = array(); if (!empty($objs)) { foreach ($objs as $o) { $output[] = $o; } } return $output; }
public function addOrUpdateRecordByArray(array $recordData, $tableName = null) { foreach ($recordData as $columnName => $columnValue) { if (is_array($columnValue)) { $table = is_null($tableName) ? $this->table : $tableName; throw new SuppliedArrayAsColumnValue("Attempting to write an array as the value for column `{$table}`.`{$columnName}`."); } } $tableName = is_null($tableName) ? $this->table : $tableName; $TableGateway = new self($this->acl, $tableName, $this->adapter); $rowExists = isset($recordData[$TableGateway->primaryKeyFieldName]); if ($rowExists) { $Update = new Update($tableName); $Update->set($recordData); $Update->where(array($TableGateway->primaryKeyFieldName => $recordData[$TableGateway->primaryKeyFieldName])); $TableGateway->updateWith($Update); Hooks::runHook('postUpdate', array($TableGateway, $recordData, $this->adapter, $this->acl)); } else { $d = $recordData; unset($d['data']); $TableGateway->insert($d); $recordData[$TableGateway->primaryKeyFieldName] = $TableGateway->getLastInsertValue(); if ($tableName == "directus_files") { $Files = new \Directus\Files\Files(); $ext = pathinfo($recordData['name'], PATHINFO_EXTENSION); $thumbnailPath = 'thumbs/THUMB_' . $recordData['name']; if ($Files->exists($thumbnailPath)) { $Files->rename($thumbnailPath, 'thumbs/' . $recordData[$this->primaryKeyFieldName] . '.' . $ext); } $updateArray = array(); if ($Files->getSettings('file_naming') == 'file_id') { $Files->rename($recordData['name'], str_pad($recordData[$this->primaryKeyFieldName], 11, "0", STR_PAD_LEFT) . '.' . $ext); $updateArray['name'] = str_pad($recordData[$this->primaryKeyFieldName], 11, "0", STR_PAD_LEFT) . '.' . $ext; $recordData['name'] = $updateArray['name']; } if (!empty($updateArray)) { $Update = new Update($tableName); $Update->set($updateArray); $Update->where(array($TableGateway->primaryKeyFieldName => $recordData[$TableGateway->primaryKeyFieldName])); $TableGateway->updateWith($Update); } } Hooks::runHook('postInsert', array($TableGateway, $recordData, $this->adapter, $this->acl)); } $columns = TableSchema::getAllNonAliasTableColumnNames($tableName); $recordData = $TableGateway->fetchAll(function ($select) use($recordData, $columns, $TableGateway) { $select->columns($columns)->limit(1); $select->where->equalTo($TableGateway->primaryKeyFieldName, $recordData[$TableGateway->primaryKeyFieldName]); })->current(); return $recordData; }
public static function fetchAllByCourseID($course_id, $objective_type = NULL) { $self = new self(); $params = array("course_id" => $course_id, "active" => "1"); if (!is_null($objective_type) && ($objective_type == "course" || $objective_type == "event")) { $params["objective_type"] = $objective_type; } return $self->fetchAll($params); }
/** * Returns the rights for the current user of each moduleId-ItemId pair. * * @param string $moduleId The module ID. * @param array $ids An array with all the IDs. * * @return array Array with 'moduleId', 'itemId', 'userId' and all the access key. */ public static function getItemRights($moduleId, $itemIds, $userId) { $values = array_fill_keys($itemIds, array()); $where = sprintf('module_id = %d AND user_id = %d AND item_id IN (%s)', (int) $moduleId, (int) $userId, implode(",", $itemIds)); $obj = new self(); $rows = $obj->fetchAll($where); foreach ($rows as $row) { // Set the current User // Use for an empty rights, if not, will be re-write $values[$row->item_id] = $row->access; } unset($obj); return $values; }
public static function searchUser($Search) { $TheUser = new self(); $Users = $TheUser->fetchAll("Name LIKE '%{$Search}%' OR Surname LIKE '%{$Search}%'"); $Ret = array(); if ($Users) { foreach ($Users as $User) { $TheUser = new self(); $Ret[] = $TheUser->copyFromDb($User); } } return $Ret; }
public static function fetchAllMedbiqInstructionalMethods() { $self = new self(); return $self->fetchAll(array("active" => 1), "=", "AND", "instructional_method"); }
public static function deletePage($IDPage) { $Page = new self(); $Rows = 0; $Children = $Page->fetchAll("IDParent = '{$IDPage}'"); if ($Children) { foreach ($Children as $Child) { $Rows += self::deletePage($Child->IDPage); } } return $Page->delete("IDPage = '{$IDPage}'") + $Rows; }
public function addOrUpdateRecordByArray(array $recordData, $tableName = null) { foreach ($recordData as $columnName => $columnValue) { if (is_array($columnValue)) { $table = is_null($tableName) ? $this->table : $tableName; throw new SuppliedArrayAsColumnValue("Attempting to write an array as the value for column `{$table}`.`{$columnName}`."); } } $tableName = is_null($tableName) ? $this->table : $tableName; $rowExists = isset($recordData['id']); $TableGateway = new self($this->acl, $tableName, $this->adapter); if ($rowExists) { $Update = new Update($tableName); $Update->set($recordData); $Update->where(array('id' => $recordData['id'])); $TableGateway->updateWith($Update); Hooks::runHook('postUpdate', array($TableGateway, $recordData, $this->adapter, $this->acl)); } else { //If we are adding a new directus_files Item, We need to do that logic // @todo: clean up/refactor saving file process if ($tableName == "directus_files") { $Storage = new \Directus\Files\Storage\Storage(); //If trying to save to temp, force to default if (!isset($recordData['storage_adapter']) || $recordData['storage_adapter'] == '' || $Storage->storageAdaptersByRole['TEMP']['id'] == $recordData['storage_adapter']) { $recordData['storage_adapter'] = $Storage->storageAdaptersByRole['DEFAULT']['id']; } $StorageAdapters = new DirectusStorageAdaptersTableGateway($this->acl, $this->adapter); //If desired Storage Adapter Exists... $filesAdapter = $StorageAdapters->fetchOneById($recordData['storage_adapter']); //Save Temp Thumbnail name for use after files record save // @todo: make file name format sanatize by default // same as uniqueName by the adapter // replacing space with underscore $originalFile = $recordData['file_name']; // we do not need it part of our records Data unset($recordData['file_name']); $recordData['name'] = str_replace(' ', '_', $recordData['name']); $info = pathinfo($recordData['name']); if (in_array($info['extension'], $this->imagickExtensions)) { $thumbnailName = "THUMB_" . $info['filename'] . '.jpg'; } else { $thumbnailName = "THUMB_" . $recordData['name']; } //If we are using files ID, Dont save until after insert if ($Storage->getFilesSettings()['file_naming'] == "file_name") { //Save the file in TEMP Storage Adapter to Designated StorageAdapter $recordData['name'] = $Storage->saveFile($recordData['name'], $recordData['storage_adapter']); // $fileData = $Storage->saveData($recordData['data'], $recordData['name'], $filesAdapter['destination']); // $recordData['name'] = $fileData['name']; } else { if ($Storage->getFilesSettings()['file_naming'] == "file_hash") { //Save the file in TEMP Storage Adapter to Designated StorageAdapter $ext = pathinfo($recordData['name'], PATHINFO_EXTENSION); $fileHashName = md5(microtime() . $recordData['name']); $newName = $Storage->saveFile($recordData['name'], $recordData['storage_adapter'], $fileHashName . '.' . $ext); $updateArray['name'] = $fileHashName . '.' . $ext; $recordData['name'] = $updateArray['name']; } } } $d = $recordData; unset($d['data']); $TableGateway->insert($d); $recordData['id'] = $TableGateway->getLastInsertValue(); if ($tableName == "directus_files") { $ext = pathinfo($recordData['name'], PATHINFO_EXTENSION); $updateArray = array(); //If using file_id saving, then update record and set name to id if ($Storage->getFilesSettings()['file_naming'] == "file_id") { $newName = $Storage->saveFile($recordData['name'], $recordData['storage_adapter'], str_pad($recordData['id'], 11, "0", STR_PAD_LEFT) . '.' . $ext); $updateArray['name'] = str_pad($recordData['id'], 11, "0", STR_PAD_LEFT) . '.' . $ext; $recordData['name'] = $updateArray['name']; } // @todo: do not make this file create twice. // file should be copied to temp and then work from there. // but is copied on "media" also on "temp" then copied back to "media" if (file_exists($filesAdapter['destination'] . $originalFile)) { unlink($filesAdapter['destination'] . $originalFile); } if (!empty($updateArray)) { $Update = new Update($tableName); $Update->set($updateArray); $Update->where(array('id' => $recordData['id'])); $TableGateway->updateWith($Update); } //Save Temp Thumbnail to Thumbnail SA using file id: $params['id'] $tempLocation = $Storage->storageAdaptersByRole['TEMP']['destination']; if (file_exists($tempLocation . $thumbnailName)) { $thumbnailDestination = $Storage->storageAdaptersByRole['THUMBNAIL']['destination']; if (in_array($ext, $this->imagickExtensions)) { $ext = 'jpg'; } $Storage->ThumbnailStorage->acceptFile($tempLocation . $thumbnailName, $recordData['id'] . "." . $ext, $thumbnailDestination); unlink($tempLocation . $thumbnailName); } } Hooks::runHook('postInsert', array($TableGateway, $recordData, $this->adapter, $this->acl)); } $columns = TableSchema::getAllNonAliasTableColumnNames($tableName); $recordData = $TableGateway->fetchAll(function ($select) use($recordData, $columns) { $select->columns($columns)->limit(1); $select->where->equalTo('id', $recordData['id']); })->current(); return $recordData; }
public static function fetchAllUnsold() { $items = new self(); return $items->fetchAll('sold <=> NULL'); }
public static function fetchAllByEventTypeID($event_type_id = null) { $self = new self(); return $self->fetchAll(array("fk_eventtype_id" => $event_type_id)); }
public static function fetchAllRecords($organisation_id = 1) { $self = new self(); $constraints = array(array("mode" => "AND", "key" => "organisation_id", "value" => $organisation_id, "method" => "="), array("mode" => "OR", "key" => "organisation_id", "value" => $organisation_id, "method" => "=")); $objs = $self->fetchAll($constraints, "=", "AND", $sort_col, $sort_order); $output = array(); if ($objs && @count($objs)) { foreach ($objs as $o) { $output[] = $o; } } return $output; }
public function addOrUpdateRecordByArray(array $recordData, $tableName = null) { foreach ($recordData as $columnName => $columnValue) { if (is_array($columnValue)) { $table = is_null($tableName) ? $this->table : $tableName; throw new SuppliedArrayAsColumnValue("Attempting to write an array as the value for column `{$table}`.`{$columnName}`."); } } $tableName = is_null($tableName) ? $this->table : $tableName; $rowExists = isset($recordData['id']); $TableGateway = new self($this->acl, $tableName, $this->adapter); if ($rowExists) { $Update = new Update($tableName); $Update->set($recordData); $Update->where(array('id' => $recordData['id'])); $TableGateway->updateWith($Update); Hooks::runHook('postUpdate', array($TableGateway, $recordData, $this->adapter, $this->acl)); } else { //If we are adding a new directus_files Item, We need to do that logic if ($tableName == "directus_files") { $Storage = new \Directus\Files\Storage\Storage(); //If trying to save to temp, force to default if (!isset($recordData['storage_adapter']) || $recordData['storage_adapter'] == '' || $Storage->storageAdaptersByRole['TEMP']['id'] == $recordData['storage_adapter']) { $recordData['storage_adapter'] = $Storage->storageAdaptersByRole['DEFAULT']['id']; } //Save Temp Thumbnail name for use after files record save $info = pathinfo($recordData['name']); if (in_array($info['extension'], $this->imagickExtensions)) { $thumbnailName = "THUMB_" . $info['filename'] . '.jpg'; } else { $thumbnailName = "THUMB_" . $recordData['name']; } //If we are using files ID, Dont save until after insert if ($Storage->getFilesSettings()['file_file_naming'] != "file_id") { //Save the file in TEMP Storage Adapter to Designated StorageAdapter $recordData['name'] = $Storage->saveFile($recordData['name'], $recordData['storage_adapter']); } } $TableGateway->insert($recordData); $recordData['id'] = $TableGateway->getLastInsertValue(); if ($tableName == "directus_files") { $ext = pathinfo($recordData['name'], PATHINFO_EXTENSION); $updateArray = array(); //If using file_id saving, then update record and set name to id if ($Storage->getFilesSettings()['file_file_naming'] == "file_id") { $newName = $Storage->saveFile($recordData['name'], $recordData['storage_adapter'], str_pad($recordData['id'], 11, "0", STR_PAD_LEFT) . '.' . $ext); $updateArray['name'] = str_pad($recordData['id'], 11, "0", STR_PAD_LEFT) . '.' . $ext; $recordData['name'] = $updateArray['name']; } //If we are using file_id titles, then set title to id if ($Storage->getFilesSettings()['file_title_naming'] == "file_id") { $updateArray['title'] = str_pad($recordData['id'], 11, "0", STR_PAD_LEFT); $recordData['title'] = $updateArray['title']; } if (!empty($updateArray)) { $Update = new Update($tableName); $Update->set($updateArray); $Update->where(array('id' => $recordData['id'])); $TableGateway->updateWith($Update); } //Save Temp Thumbnail to Thumbnail SA using file id: $params['id'] $tempLocation = $Storage->storageAdaptersByRole['TEMP']['destination']; if (file_exists($tempLocation . $thumbnailName)) { $thumbnailDestination = $Storage->storageAdaptersByRole['THUMBNAIL']['destination']; if (in_array($ext, $this->imagickExtensions)) { $ext = 'jpg'; } $Storage->ThumbnailStorage->acceptFile($tempLocation . $thumbnailName, $recordData['id'] . "." . $ext, $thumbnailDestination); unlink($tempLocation . $thumbnailName); } } Hooks::runHook('postInsert', array($TableGateway, $recordData, $this->adapter, $this->acl)); } $columns = TableSchema::getAllNonAliasTableColumnNames($tableName); $recordData = $TableGateway->fetchAll(function ($select) use($recordData, $columns) { $select->columns($columns)->limit(1); $select->where->equalTo('id', $recordData['id']); })->current(); return $recordData; }
public static function fetchAllRecords($module, $action, $action_field, $proxy_id = NULL) { $self = new self(); $constraints = array(array("mode" => "AND", "key" => "module", "value" => $module, "method" => "="), array("mode" => "AND", "key" => "action", "value" => $action, "method" => "="), array("mode" => "AND", "key" => "action_field", "value" => $action_field, "method" => "=")); if (!is_null($proxy_id)) { $constraints[] = array("mode" => "AND", "key" => "proxy_id", "value" => $proxy_id, "method" => "="); } $objs = $self->fetchAll($constraints, "=", "AND", $sort_col, $sort_order); $output = array(); if (!empty($objs)) { foreach ($objs as $o) { $output[] = $o; } } return $output; }