/** * Saving information about customer * * @param Mage_Log_Model_Visitor $visitor * * @return Mage_Log_Model_Resource_Visitor */ protected function _saveCustomerInfo($visitor) { $adapter = $this->_getWriteAdapter(); if ($visitor->getDoCustomerLogout() && ($logId = $visitor->getCustomerLogId())) { $resource = Mage::getSingleton('core/resource'); $connection = $resource->getConnection('core_read'); $select = new Zend_Db_Select($connection); $select->from($resource->getTableName('log/customer')); $select->reset(Zend_Db_Select::COLUMNS); $select->columns('login_at'); $select->where('log_id = ?', $logId); $loginAt = $connection->fetchOne($select); if (!$loginAt) { return parent::_saveCustomerInfo($visitor); } $data = new Varien_Object(array('login_at' => $loginAt, 'logout_at' => Mage::getSingleton('core/date')->gmtDate(), 'store_id' => (int) Mage::app()->getStore()->getId())); $bind = $this->_prepareDataForTable($data, $this->getTable('log/customer')); $condition = array('log_id = ?' => (int) $logId); $adapter->update($this->getTable('log/customer'), $bind, $condition); $visitor->setDoCustomerLogout(false); $visitor->setCustomerId(null); $visitor->setCustomerLogId(null); } else { return parent::_saveCustomerInfo($visitor); } return $this; }
/** * Columns * * @param unknown_type $name * @param unknown_type $cond * @return WeFlex_Db_Model */ public function columns($cols) { $this->_selector->reset(Zend_Db_Select::COLUMNS); foreach ($cols as $col) { $this->_selector->columns($col, null); } return $this; }
/** * Render sql select orders * * @return Varien_Data_Collection_Db */ protected function _renderOrders() { if (!$this->_isOrdersRendered) { $this->_select->reset(Zend_Db_Select::ORDER); foreach ($this->_orders as $field => $direction) { $this->_select->order(new Zend_Db_Expr($field . ' ' . $direction)); } $this->_isOrdersRendered = true; } return $this; }
/** * Alias * * Sets an internal alias variable that is used if, and only if, we haven't operated a method on the internal * $_select variable. This could be changed in the future so that alias() can be called at any time regardless, * but that is more difficult and requires a deeper understanding of Zend_Db_Select internals. * * @access public * @param string $alias - The alias to use for the table. * @return SimpleDb_List object. */ public function alias($alias) { $this->_alias = $alias; // In order to do the alias, we have to clear the FROM. $this->_select->reset(Zend_Db_Select::FROM)->reset(Zend_Db_Select::COLUMNS)->from(array($this->_alias => $this->tableName()), $this->_fields); // Now, since we cleared the FROM, we should go through and re-perform all the joins that were cleared out as well. $joinHistory = $this->_joinHistory; // Clearing the joinHistory because it will get re-populated when we perform the joins below. unset($this->_joinHistory); foreach ($joinHistory as $join) { call_user_func_array(array($this->_select, $join['function']), $join['arguments']); } return $this; }
function onInstall() { // // install content areas // $db = $this->getDb(); $select = new Zend_Db_Select($db); //INSERT INTO `engine4_core_content` (`content_id`, `page_id`, `type`, `name`, `parent_content_id`, `order`, `params`) VALUES // profile page $select->from('engine4_core_pages')->where('name = ?', 'user_profile_index')->limit(1); $page_id = $select->query()->fetchObject()->page_id; // forum.profile-forum-posts // Check if it's already been placed $select = new Zend_Db_Select($db); $select->from('engine4_core_content')->where('page_id = ?', $page_id)->where('type = ?', 'widget')->where('name = ?', 'forum.profile-forum-posts'); $info = $select->query()->fetch(); if (empty($info)) { // container_id (will always be there) $select = new Zend_Db_Select($db); $select->from('engine4_core_content')->where('page_id = ?', $page_id)->where('type = ?', 'container')->limit(1); $container_id = $select->query()->fetchObject()->content_id; // middle_id (will always be there) $select = new Zend_Db_Select($db); $select->from('engine4_core_content')->where('parent_content_id = ?', $container_id)->where('type = ?', 'container')->where('name = ?', 'middle')->limit(1); $middle_id = $select->query()->fetchObject()->content_id; // tab_id (tab container) may not always be there $select->reset('where')->where('type = ?', 'widget')->where('name = ?', 'core.container-tabs')->where('page_id = ?', $page_id)->limit(1); $tab_id = $select->query()->fetchObject(); if ($tab_id && @$tab_id->content_id) { $tab_id = $tab_id->content_id; } else { $tab_id = null; } // tab on profile $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'forum.profile-forum-posts', 'parent_content_id' => $tab_id ? $tab_id : $middle_id, 'order' => 9, 'params' => '{"title":"Forum Posts","titleCount":true}')); } parent::onInstall(); }
/** * Resets query limit * * @return Bvb_Grid_Source_Zend_Select */ public function resetLimit() { $this->_select->reset('limitcount'); $this->_select->reset('limitoffset'); return $this; }
/** * Set WHERE clause that checks for slug existence. * @param Zend_Db_Select $select * @param String $slugField * @param String $slug * @param Garp_Model_Db $model * @param String $lang * @return Void */ protected function _setWhereClause(Zend_Db_Select &$select, $slugField, $slug, Garp_Model_Db $model, $lang = null) { $slugField = $model->getAdapter()->quoteIdentifier($slugField); $select->reset(Zend_Db_Select::WHERE)->where($slugField . ' = ?', $slug); if ($lang) { $select->where(Garp_Model_Behavior_Translatable::LANG_COLUMN . ' = ?', $lang); } }
protected function _addUserProfileContent() { $db = $this -> getDb(); $select = new Zend_Db_Select($db); // profile page $select -> from('engine4_core_pages') -> where('name = ?', 'user_profile_index') -> limit(1); $page_id = $select -> query() -> fetchObject() -> page_id; // video.profile-videos // Check if it's already been placed $select = new Zend_Db_Select($db); $select -> from('engine4_core_content') -> where('page_id = ?', $page_id) -> where('type = ?', 'widget') -> where('name = ?', 'ynvideo.profile-videos'); $infoProfileVideos = $select -> query() -> fetch(); if (empty($infoProfileVideos)) { $this -> _insertWidgetToProfileContent($page_id, 'ynvideo.profile-videos', '{"title":"Videos","titleCount":true}', 12); } // check if the profile video widget of SE video existed or not, // it it is existed, then delete it from the user profie page $select = new Zend_Db_Select($db); $select -> from('engine4_core_content') -> where('page_id = ?', $page_id) -> where('type = ?', 'widget') -> where('name = ?', 'video.profile-videos'); $infoSEProfileVideos = $select -> query() -> fetch(); if (!empty($infoSEProfileVideos)) { $db -> delete('engine4_core_content', array("content_id = {$infoSEProfileVideos['content_id']}")); } // video.profile-favorite-videos // Check if it's already been placed $select -> reset('where') -> where('page_id = ?', $page_id) -> where('type = ?', 'widget') -> where('name = ?', 'ynvideo.profile-favorite-videos'); $infoProfileFavoriteVideos = $select -> query() -> fetch(); if (empty($infoProfileFavoriteVideos)) { $this -> _insertWidgetToProfileContent($page_id, 'ynvideo.profile-favorite-videos', '{"title":"Favorite Videos","titleCount":true}', 13); } // video.profile-video-playlists // Check if it's already been placed $select -> reset('where') -> where('page_id = ?', $page_id) -> where('type = ?', 'widget') -> where('name = ?', 'ynvideo.profile-video-playlists'); $infoProfileFavoriteVideos = $select -> query() -> fetch(); if (empty($infoProfileFavoriteVideos)) { $this -> _insertWidgetToProfileContent($page_id, 'ynvideo.profile-video-playlists', '{"title":"Video Playlists","titleCount":true}', 14); } }
function onInstall() { // // install content areas // $db = $this->getDb(); $select = new Zend_Db_Select($db); //INSERT INTO `engine4_core_content` (`content_id`, `page_id`, `type`, `name`, `parent_content_id`, `order`, `params`) VALUES // profile page $select->from('engine4_core_pages')->where('name = ?', 'user_profile_index')->limit(1); $page_id = $select->query()->fetchObject()->page_id; // group.profile-groups // Check if it's already been placed $select = new Zend_Db_Select($db); $select->from('engine4_core_content')->where('page_id = ?', $page_id)->where('type = ?', 'widget')->where('name = ?', 'group.profile-groups'); $info = $select->query()->fetch(); if (empty($info)) { // container_id (will always be there) $select = new Zend_Db_Select($db); $select->from('engine4_core_content')->where('page_id = ?', $page_id)->where('type = ?', 'container')->limit(1); $container_id = $select->query()->fetchObject()->content_id; // middle_id (will always be there) $select = new Zend_Db_Select($db); $select->from('engine4_core_content')->where('parent_content_id = ?', $container_id)->where('type = ?', 'container')->where('name = ?', 'middle')->limit(1); $middle_id = $select->query()->fetchObject()->content_id; // tab_id (tab container) may not always be there $select->reset('where')->where('type = ?', 'widget')->where('name = ?', 'core.container-tabs')->where('page_id = ?', $page_id)->limit(1); $tab_id = $select->query()->fetchObject(); if ($tab_id && @$tab_id->content_id) { $tab_id = $tab_id->content_id; } else { $tab_id = null; } // tab on profile $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'group.profile-groups', 'parent_content_id' => $tab_id ? $tab_id : $middle_id, 'order' => 9, 'params' => '{"title":"Groups","titleCount":true}')); } // // Group main page // // page // Check if it's already been placed $select = new Zend_Db_Select($db); $select->from('engine4_core_pages')->where('name = ?', 'group_profile_index')->limit(1); $info = $select->query()->fetch(); if (empty($info)) { $db->insert('engine4_core_pages', array('name' => 'group_profile_index', 'displayname' => 'Group Profile', 'title' => 'Group Profile', 'description' => 'This is the profile for an group.', 'custom' => 0)); $page_id = $db->lastInsertId('engine4_core_pages'); // containers $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'container', 'name' => 'main', 'parent_content_id' => null, 'order' => 1, 'params' => '')); $container_id = $db->lastInsertId('engine4_core_content'); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'container', 'name' => 'middle', 'parent_content_id' => $container_id, 'order' => 3, 'params' => '')); $middle_id = $db->lastInsertId('engine4_core_content'); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'container', 'name' => 'left', 'parent_content_id' => $container_id, 'order' => 1, 'params' => '')); $left_id = $db->lastInsertId('engine4_core_content'); // middle column $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'core.container-tabs', 'parent_content_id' => $middle_id, 'order' => 2, 'params' => '{"max":"6"}')); $tab_id = $db->lastInsertId('engine4_core_content'); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'group.profile-status', 'parent_content_id' => $middle_id, 'order' => 1, 'params' => '')); // left column $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'group.profile-photo', 'parent_content_id' => $left_id, 'order' => 1, 'params' => '')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'group.profile-options', 'parent_content_id' => $left_id, 'order' => 2, 'params' => '')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'group.profile-info', 'parent_content_id' => $left_id, 'order' => 3, 'params' => '')); // tabs $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'activity.feed', 'parent_content_id' => $tab_id, 'order' => 1, 'params' => '{"title":"Updates"}')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'group.profile-members', 'parent_content_id' => $tab_id, 'order' => 2, 'params' => '{"title":"Members","titleCount":true}')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'group.profile-photos', 'parent_content_id' => $tab_id, 'order' => 3, 'params' => '{"title":"Photos","titleCount":true}')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'group.profile-discussions', 'parent_content_id' => $tab_id, 'order' => 4, 'params' => '{"title":"Discussions","titleCount":true}')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'core.profile-links', 'parent_content_id' => $tab_id, 'order' => 5, 'params' => '{"title":"Links","titleCount":true}')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'group.profile-events', 'parent_content_id' => $tab_id, 'order' => 6, 'params' => '{"title":"Events","titleCount":true}')); } parent::onInstall(); }
/** * Returns an array of objects queried from the given t41_Object_Collection instance parameters * * The given collection is populated if it comes empty of members. * * In any other case, this method doesn't directly populate the collection. This action is under the responsability of * the caller. For example, the t41_Object_Collection::find() method takes care of it. * * @param t41\ObjectModel\Collection $collection * @param boolean|array $returnCount true = counting, array = stats on listed properties * @param string $subOp complex operation like SUM or AVG * @return array */ public function find(ObjectModel\Collection $collection, $returnCount = false, $subOp = null) { $this->_class = $class = $collection->getDataObject()->getClass(); $table = $this->_getTableFromClass($class); if (!$table) { throw new Exception('MISSING_DBTABLE_PARAM'); } // primary key is either part of the mapper configuration or 'id' $pkey = $this->_mapper ? $this->_mapper->getPrimaryKey($class) : \t41\Backend::DEFAULT_PKEY; if (is_array($pkey)) { $composite = array(); /* @var $obj t41\Backend\Key */ foreach ($pkey as $obj) { $composite[] = sprintf('TRIM(%s)', $table . '.' . $obj->getName()); $composite[] = Backend\Mapper::VALUES_SEPARATOR; } $pkey = sprintf("CONCAT(%s) AS %s", implode(',', $composite), Backend::DEFAULT_PKEY); } else { $pkey = $table . '.' . $pkey; } $this->_connect(); /* @var $select \Zend_Db_Select */ $this->_select = $this->_ressource->select(); // detect if query is of stat-kind if ($returnCount) { switch ($subOp) { case ObjectModel::CALC_SUM: $expressions = array(); foreach ($returnCount as $propKey => $property) { $prop = $this->_mapper ? $this->_mapper->propertyToDatastoreName($class, $propKey) : $propKey; $expressions[] = sprintf('SUM(%s.%s)', $table, $prop); } $subOpExpr = implode('+', $expressions); break; case ObjectModel::CALC_AVG: $subOpExpr = sprintf('AVG(%s)', $returnCount); break; default: $subOpExpr = 'COUNT(*)'; break; } $this->_select->from($table, new \Zend_Db_Expr($subOpExpr . " AS " . \t41\Backend::MAX_ROWS_IDENTIFIER)); } else { $this->_select->distinct(); $this->_select->from($table, $pkey); } $this->_alreadyJoined = array(); /* @var $condition t41\Backend\Condition */ foreach ($collection->getConditions() as $conditionArray) { // combo conditions if ($conditionArray[0] instanceof Condition\Combo) { $statement = array(); foreach ($conditionArray[0]->getConditions() as $condition) { $statement[] = $this->_parseCondition($condition[0], $this->_select, $table); } $statement = implode(' OR ', $statement); switch ($conditionArray[1]) { case Condition::MODE_OR: $this->_select->orWhere($statement); break; case Condition::MODE_AND: default: $this->_select->where($statement); break; } continue; } // optional table where the column may be $jtable = ''; // condition object is in the first key $condition = $conditionArray[0]; /* does condition contain another condition object ? */ if ($condition->isRecursive()) { while ($condition->isRecursive()) { $property = $condition->getProperty(); $parent = $property->getParent() ? $property->getParent()->getId() : $table; $condition = $condition->getCondition(); if ($jtable) { $parentTable = $jtable; } else { if ($parent) { $parentTable = $this->_mapper ? $this->_mapper->getDatastore($parent) : $parent; } else { $parentTable = $table; } } $jtable = $this->_mapper ? $this->_mapper->getDatastore($property->getParameter('instanceof')) : $this->_getTableFromClass($property->getParameter('instanceof')); /* column name in left table */ $jlkey = $this->_mapper ? $this->_mapper->propertyToDatastoreName($class, $property->getId()) : $property->getId(); $uniqext = $jtable . '__joined_for__' . $jlkey; if (in_array($uniqext, $this->_alreadyJoined)) { $class = $property->getParameter('instanceof'); $jtable = $uniqext; continue; } /* pkey name in joined table */ $jpkey = $this->_mapper ? $this->_mapper->getPrimaryKey($property->getParameter('instanceof')) : Backend::DEFAULT_PKEY; $join = sprintf("%s.%s = %s.%s", $parentTable, $jlkey, $uniqext, $jpkey); $this->_select->joinLeft($jtable . " AS {$uniqext}", $join, array()); $this->_alreadyJoined[$jtable] = $uniqext; //$jtable; $jtable = $uniqext; $class = $property->getParameter('instanceof'); } } $property = $condition->getProperty(); if ($property instanceof Property\ObjectProperty) { // no join if object is stored in a different backend ! // @todo improve this part if (ObjectModel::getObjectBackend($property->getParameter('instanceof'))->getAlias() != $this->_uri->getAlias()) { $clauses = $condition->getClauses(); if ($clauses[0]['value'] != Condition::NO_VALUE) { $clauses[0]['operator'] = Condition::OPERATOR_ENDSWITH | Condition::OPERATOR_EQUAL; $condition->setClauses($clauses); } $field = $this->_mapper ? $this->_mapper->propertyToDatastoreName($this->_class, $property->getId()) : $property->getId(); } else { // which table to join with ? (in case of condition is last element of a recursion) $jtable2 = $jtable ? $jtable : $table; $jtable = $this->_mapper ? $this->_mapper->getDatastore($property->getParameter('instanceof')) : $this->_getTableFromClass($property->getParameter('instanceof')); $leftkey = $this->_mapper ? $this->_mapper->propertyToDatastoreName($class, $property->getId()) : $property->getId(); $field = $rightkey = $this->_mapper ? $this->_mapper->getPrimaryKey($property->getParameter('instanceof')) : Backend::DEFAULT_PKEY; $uniqext = $jtable . '__joined_for__' . $leftkey; if (!in_array($uniqext, $this->_alreadyJoined)) { $join = sprintf("%s.%s = %s.%s", $jtable2, $leftkey, $uniqext, is_array($rightkey) ? $rightkey[0] : $rightkey); $this->_select->joinLeft($jtable . " AS {$uniqext}", $join, array()); $this->_alreadyJoined[$jtable] = $uniqext; } $jtable = $uniqext; } } else { if ($property instanceof Property\CollectionProperty) { // handling of conditions based on collection limited to withMembers() and withoutMembers() $leftkey = $property->getParameter('keyprop'); $field = $property->getId(); $subSelect = $this->_ressource->select(); $subseltbl = $this->_mapper ? $this->_mapper->getDatastore($property->getParameter('instanceof')) : $this->_getTableFromClass($property->getParameter('instanceof')); $subSelect->from($subseltbl, new \Zend_Db_Expr(sprintf("COUNT(%s)", $leftkey))); $join = sprintf("%s.%s = %s", $subseltbl, $leftkey, $pkey); $subSelect->where($join); $statement = $this->_buildConditionStatement(new \Zend_Db_Expr(sprintf("(%s)", $subSelect)), $condition->getClauses(), $conditionArray[1]); $this->_select->where($statement); continue; } else { $field = $property->getId(); if ($this->_mapper) { $field = $this->_mapper->propertyToDatastoreName($class, $field); } } } /* convert identifier tag to the valid primary key */ if ($field == ObjectUri::IDENTIFIER) { // @todo handle multiple keys from mapper $field = $table . '.'; $key = $this->_mapper ? $this->_mapper->getPrimaryKey($class) : Backend::DEFAULT_PKEY; $field .= is_array($key) ? $key[0] : $key; } else { if ($jtable) { if (array_key_exists($jtable, $this->_alreadyJoined)) { $field = $this->_alreadyJoined[$jtable] . '.' . $field; } else { $tmp = $jtable . '.'; $tmp .= is_array($field) ? $field[0] : $field; $field = $tmp; } } else { if (array_key_exists($table, $this->_alreadyJoined)) { $field = $this->_alreadyJoined[$table] . '.' . $field; } else { $field = $table . '.' . $field; } } } if ($field instanceof Key) { $field = $table . '.' . $field->getName(); } // protect DateProperty() with setted timepart parameter from misuse if ($property instanceof DateProperty && $property->getParameter('timepart') == true) { $field = "DATE({$field})"; } $statement = $this->_buildConditionStatement($field, $condition->getClauses(), $conditionArray[1]); switch ($conditionArray[1]) { case Condition::MODE_OR: $this->_select->orWhere($statement); break; case Condition::MODE_AND: default: $this->_select->where($statement); break; } } // Adjust query based on returnCount if ($returnCount) { if (is_array($returnCount)) { if ($subOp) { } else { // return count on grouped columns foreach ($returnCount as $key => $property) { $fieldmodifier = null; if ($this->_mapper) { $class = $property->getParent() ? $property->getParent()->getId() : $collection->getDataObject()->getClass(); $field = $this->_mapper->propertyToDatastoreName($class, $property->getId()); } else { $field = $property->getId(); } if ($property instanceof ObjectProperty) { // join with $key if necessary if (strstr($key, '.') !== false) { $leftPart = substr($key, 0, strpos($key, '.')); $intermediateProp = $collection->getDataObject()->getProperty($leftPart); $fieldmodifier = $this->_join($intermediateProp, $table) . '.' . $field; } } // limit date grouping to date part, omitting possible hour part if ($property instanceof DateProperty) { $fieldmodifier = "DATE({$field})"; } $this->_select->group($fieldmodifier ? $fieldmodifier : $field); $this->_select->columns(array($field => $fieldmodifier ? $fieldmodifier : $field)); } } } else { $this->_select->reset('group'); } } else { $this->_select->limit($collection->getBoundaryBatch() != -1 ? $collection->getBoundaryBatch() : null, $collection->getBoundaryOffset()); /** * Sorting part */ foreach ($collection->getSortings() as $sorting) { $slUniqext = $slTable = null; // Specific cases first // @todo find a better way to sort on meta properties if ($sorting[0]->getId() == ObjectUri::IDENTIFIER || $sorting[0] instanceof MetaProperty) { $id = Backend::DEFAULT_PKEY; $this->_select->order(new \Zend_Db_Expr($table . '.' . $id . ' ' . $sorting[1])); continue; } else { if ($sorting[0] instanceof Property\CollectionProperty) { // handling of conditions based on collection limited to withMembers() and withoutMembers() $leftkey = $sorting[0]->getParameter('keyprop'); //$field = $property->getId(); $subSelect = $this->_ressource->select(); $subseltbl = $this->_mapper ? $this->_mapper->getDatastore($sorting[0]->getParameter('instanceof')) : $this->_getTableFromClass($sorting[0]->getParameter('instanceof')); $subSelect->from($subseltbl, new \Zend_Db_Expr(sprintf("COUNT(%s)", $leftkey))); $join = sprintf("%s.%s = %s", $subseltbl, $leftkey, $pkey); $subSelect->where($join); // $statement = $this->_buildConditionStatement(new \Zend_Db_Expr(sprintf("(%s)", $subSelect)), $condition->getClauses(), $conditionArray[1]); $this->_select->order(new \Zend_Db_Expr('(' . $subSelect->__toString() . ') ' . $sorting[1])); continue; } else { if ($sorting[0] instanceof Property\ObjectProperty) { // find which property to sort by if ($sorting[0]->getParameter('sorting')) { $sprops = array_keys($sorting[0]->getParameter('sorting')); } else { // try to sort with properties used to display value if (substr($sorting[0]->getParameter('display'), 0, 1) == '[') { // @todo extract elements of pattern to order from them ? $sprops = array('id'); } else { $sprops = explode(',', $sorting[0]->getParameter('display')); } } // sorting property belongs to a second-level join if ($sorting[0]->getParent()->getClass() != $collection->getClass()) { $leftkey = 'commande'; //$this->_mapper ? $this->_mapper->propertyToDatastoreName($collection->getDataObject()->getClass(), $sorting[0]->getParent()getId()) : $sorting[0]->getId(); $class = $sorting[0]->getParent()->getClass(); $stable = $this->_getTableFromClass($class); $sbackend = ObjectModel::getObjectBackend($class); // Property to sort from is in a different backend from current one if ($sbackend->getAlias() != $this->getAlias()) { // We presume that the current backend is allowed to connect to the remote one // Should we raise an exception instead ? $stable = $sbackend->getUri()->getDatabase() . '.' . $stable; } $field = $sorting[0]->getId(); $rightkey = $this->_mapper ? $this->_mapper->getPrimaryKey($class) : Backend::DEFAULT_PKEY; $uniqext = $stable . '__joined_for__' . $leftkey; if (!in_array($uniqext, $this->_alreadyJoined)) { if (is_array($rightkey)) { foreach ($rightkey as $rightkeyObj) { $join = sprintf("%s.%s = %s.%s", $table, $leftkey, $uniqext, $rightkeyObj->getName()); } } else { $join = sprintf("%s.%s = %s.%s", $table, $leftkey, $uniqext, $rightkey); } $this->_select->joinLeft("{$stable} AS {$uniqext}", $join, array()); $this->_alreadyJoined[$stable] = $uniqext; } $slTable = $this->_getTableFromClass($sorting[0]->getParameter('instanceof')); $slUniqext = $uniqext; } $leftkey = $this->_mapper ? $this->_mapper->propertyToDatastoreName($collection->getDataObject()->getClass(), $sorting[0]->getId()) : $sorting[0]->getId(); $class = $sorting[0]->getParameter('instanceof'); $stable = isset($slTable) ? $slTable : $this->_getTableFromClass($class); $sbackend = ObjectModel::getObjectBackend($class); // Property to sort from is in a different backend from current one if ($sbackend->getAlias() != $this->getAlias()) { // We presume that the current backend is allowed to connect to the remote one // Should we raise an exception instead ? $stable = $sbackend->getUri()->getDatabase() . '.' . $stable; } $field = $sorting[0]->getId(); $rightkey = $this->_mapper ? $this->_mapper->getPrimaryKey($class) : Backend::DEFAULT_PKEY; $uniqext = $stable . '__joined_for__' . $leftkey; if (!in_array($uniqext, $this->_alreadyJoined)) { if (is_array($rightkey)) { foreach ($rightkey as $rightkeyObj) { $join = sprintf("%s.%s = %s.%s", $table, $leftkey, $uniqext, $rightkeyObj->getName()); } } else { $join = sprintf("%s.%s = %s.%s", isset($slUniqext) ? $slUniqext : $table, $leftkey, $uniqext, $rightkey); } $this->_select->joinLeft("{$stable} AS {$uniqext}", $join, array()); $this->_alreadyJoined[$stable] = $uniqext; } foreach ($sprops as $sprop) { if ($this->_mapper) { $sfield = $this->_mapper->propertyToDatastoreName($class, $sprop); } else { $sfield = $sprop; } $sortingExpr = $this->_alreadyJoined[$stable] . '.' . $sfield; if (isset($sorting[2]) && !empty($sorting[2])) { $sortingExpr = sprintf('%s(%s)', $sorting[2], $sortingExpr); } $this->_select->order(new \Zend_Db_Expr($sortingExpr . ' ' . $sorting[1])); } continue; } } } // default sorting on a different table $class = $sorting[0]->getParent() ? $sorting[0]->getParent()->getClass() : $collection->getDataObject()->getClass(); $stable = $this->_getTableFromClass($class); if ($this->_mapper) { $sfield = $this->_mapper->propertyToDatastoreName($class, $sorting[0]->getId()); } else { $field = $sorting[0]; $sfield = $field->getId(); } // add a left join if the sorting field belongs to a table not yet part of the query if ($stable != $table) { // get the property id from the class name $tfield = isset($sorting[3]) ? $sorting[3] : $collection->getDataObject()->getObjectPropertyId($class); $leftkey = $this->_mapper ? $this->_mapper->propertyToDatastoreName($class, $tfield) : $tfield; $rightkey = $this->_mapper ? $this->_mapper->getPrimaryKey($field->getParameter('instanceof')) : Backend::DEFAULT_PKEY; $uniqext = $stable . '__joined_for__' . $leftkey; if (!in_array($uniqext, $this->_alreadyJoined)) { $join = sprintf("%s.%s = %s.%s", $table, $leftkey, $uniqext, $rightkey); $this->_select->joinLeft("{$stable} AS {$uniqext}", $join, array()); $this->_alreadyJoined[$stable] = $uniqext; } $sortingExpr = $this->_alreadyJoined[$stable] . '.' . $sfield; } else { $sortingExpr = $stable . '.' . $sfield; } if (isset($sorting[2]) && !empty($sorting[2])) { $sortingExpr = sprintf('%s(%s)', $sorting[2], $sortingExpr); } $this->_select->order(new \Zend_Db_Expr('TRIM(' . $sortingExpr . ') ' . $sorting[1])); } } $result = array(); $context = array('table' => $table); try { if (true && $returnCount == false) { $this->_select->columns($this->_getColumns($collection->getDataObject())); } $result = $this->_ressource->fetchAll($this->_select); } catch (\Zend_Db_Exception $e) { $context['error'] = $e->getMessage(); $this->_setLastQuery($this->_select->__toString(), $this->_select->getPart('where'), $context); return false; } $this->_setLastQuery($this->_select->__toString(), $this->_select->getPart('where'), $context); if ($returnCount !== false) { return is_array($returnCount) ? $result : $result[0][Backend::MAX_ROWS_IDENTIFIER]; } // convert array of primary keys to strings foreach ($result as $key => $val) { // $result[$key] = implode(Backend\Mapper::VALUES_SEPARATOR, $val); } /* prepare base of object uri */ $uri = new ObjectModel\ObjectUri(); $uri->setBackendUri($this->_uri); $uri->setClass($collection->getDataObject()->getClass()); $uri->setUrl($this->_database . '/' . $table . '/'); return $collection->populate($result, $uri); //return $this->_populateCollection($result, $collection, $uri); }
/** * Modify the order clause to reflect the record's weight * @param Zend_Db_Select $select */ public function addOrderClause(Zend_Db_Select &$select) { // Distill the WHERE class from the Select object $where = $select->getPart(Zend_Db_Select::WHERE); // Save the existing ORDER clause. $originalOrder = $select->getPart(Zend_Db_Select::ORDER); $select->reset(Zend_Db_Select::ORDER); $alias = ''; if ($this->_modelAlias) { $alias = $this->_modelAlias . '.'; } /** * If a registered foreign key (see self::_relationConfig) is found, this query is * considered to be a related fetch() command, and an ORDER BY clause is added with * the registered weight column. */ foreach ($where as $w) { foreach ($this->_relationConfig as $model => $modelRelationConfig) { if (strpos($w, $modelRelationConfig[self::FOREIGN_KEY_COLUMN_KEY]) !== false) { $select->order($alias . $modelRelationConfig[self::WEIGHT_COLUMN_KEY] . ' DESC'); } } } // Return the existing ORDER clause, only this time '<weight-column> DESC' will be in front of it foreach ($originalOrder as $order) { // [0] = column, [1] = direction if (is_array($order)) { $order = $order[0] . ' ' . $order[1]; } $select->order($order); } }
function onInstall() { // // install content areas // $db = $this->getDb(); $select = new Zend_Db_Select($db); // profile page $select->from('engine4_core_pages')->where('name = ?', 'user_profile_index')->limit(1); $page_id = $select->query()->fetchObject()->page_id; // video.profile-videos // Check if it's already been placed $select = new Zend_Db_Select($db); $select->from('engine4_core_content')->where('page_id = ?', $page_id)->where('type = ?', 'widget')->where('name = ?', 'video.profile-videos'); $info = $select->query()->fetch(); if (empty($info)) { // container_id (will always be there) $select = new Zend_Db_Select($db); $select->from('engine4_core_content')->where('page_id = ?', $page_id)->where('type = ?', 'container')->limit(1); $container_id = $select->query()->fetchObject()->content_id; // middle_id (will always be there) $select = new Zend_Db_Select($db); $select->from('engine4_core_content')->where('parent_content_id = ?', $container_id)->where('type = ?', 'container')->where('name = ?', 'middle')->limit(1); $middle_id = $select->query()->fetchObject()->content_id; // tab_id (tab container) may not always be there $select->reset('where')->where('type = ?', 'widget')->where('name = ?', 'core.container-tabs')->where('page_id = ?', $page_id)->limit(1); $tab_id = $select->query()->fetchObject(); if ($tab_id && @$tab_id->content_id) { $tab_id = $tab_id->content_id; } else { $tab_id = null; } // tab on profile $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'video.profile-videos', 'parent_content_id' => $tab_id ? $tab_id : $middle_id, 'order' => 12, 'params' => '{"title":"Videos","titleCount":true}')); } // Check ffmpeg path for correctness if (function_exists('exec') && function_exists('shell_exec')) { // Api is not available //$ffmpeg_path = Engine_Api::_()->getApi('settings', 'core')->video_ffmpeg_path; $ffmpeg_path = $db->select()->from('engine4_core_settings', 'value')->where('name = ?', 'video.ffmpeg.path')->limit(1)->query()->fetchColumn(0); $output = null; $return = null; if (!empty($ffmpeg_path)) { exec($ffmpeg_path . ' -version', $output, $return); } // Try to auto-guess ffmpeg path if it is not set correctly $ffmpeg_path_original = $ffmpeg_path; if (empty($ffmpeg_path) || $return > 0 || stripos(join('', $output), 'ffmpeg') === false) { $ffmpeg_path = null; // Windows if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { // @todo } else { $output = null; $return = null; @exec('which ffmpeg', $output, $return); if (0 == $return) { $ffmpeg_path = array_shift($output); $output = null; $return = null; exec($ffmpeg_path . ' -version', $output, $return); if (0 == $return) { $ffmpeg_path = null; } } } } if ($ffmpeg_path != $ffmpeg_path_original) { $count = $db->update('engine4_core_settings', array('value' => $ffmpeg_path), array('name = ?' => 'video.ffmpeg.path')); if ($count === 0) { try { $db->insert('engine4_core_settings', array('value' => $ffmpeg_path, 'name' => 'video.ffmpeg.path')); } catch (Exception $e) { } } } } parent::onInstall(); }
protected function _modifySearchQuery(Zend_Db_Select &$select, $model) { $where = $select->getPart(Zend_Db_Select::WHERE); if (!$where) { return; } $select->reset(Zend_Db_Select::WHERE); foreach ($where as $clause) { // Check if it's a search query if (stripos($clause, 'like') !== false) { preg_match('/%.*?%/', $clause, $matches); if (!empty($matches[0])) { $clause = $this->_cleanClause($clause); $clause .= ' OR ' . $this->_joinCmsSearchQuery($model, $select, $matches[0]); } } // re-attach clause $whereBoolType = $this->_determineAndOrOr($clause); $clause = preg_replace('/(^OR|^AND)/', '', $clause); $clause = $this->_cleanClause($clause); if ($whereBoolType === 'OR') { $select->orWhere($clause); continue; } $select->where($clause); } }
/** * * Public service for grouping treatment * @param Zend_Db_Adapter $adapter * @param string $tablePrefix * @param Zend_Db_Select $select */ public static function traitGroup($adapter, $tablePrefix, Zend_Db_Select $select) { $group = $select->getPart(Zend_Db_Select::GROUP); //if (empty($group)) return; $order = $select->getPart(Zend_Db_Select::ORDER); $columns = $select->getPart(Zend_Db_Select::COLUMNS); try { //$column is an array where 0 is table, 1 is field and 2 is alias foreach ($columns as $column) { $field = implode('.', $column); if (!in_array($field, $group)) { // replaces * by each name of column if ($column[1] == '*') { $tableFields = $adapter->describeTable($tablePrefix . $column[0]); foreach ($tableFields as $columnName => $schema) { // adds columns into group by clause (table.field) // checks if field has a function (that must be an aggregation) $element = "{$column[0]}.{$columnName}"; if (!in_array($element, $group) && !preg_match('/\\(.*\\)/', $element)) { $group[] = $element; } } } else { // adds column into group by clause (table.field) $element = "{$column[0]}.{$column[1]}"; if (!preg_match('/\\(.*\\)/', $element)) { $group[] = $element; } else { if (substr($column[1], 0, 10) == "(CASE WHEN") { $group[] = $column[1]; } } } } } foreach ($order as $column) { $field = $column[0]; if (preg_match('/.*\\..*/', $field) && !in_array($field, $group)) { // adds column into group by clause (table.field) $group[] = $field; } } $select->reset(Zend_Db_Select::GROUP); $select->group($group); } catch (Exception $e) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Exception: ' . $e->getMessage() . ' Trace: ' . $e->getTraceAsString()); } return $select; }
/** * Calculate number of purchase from invited customers * * @param Zend_Db_Select $select * @return bool|int */ protected function _getPurchaseNumber($select) { /* var $select Zend_Db_Select */ $select->reset(Zend_Db_Select::COLUMNS)->joinRight(array('o' => $this->getTable('sales/order')), 'o.customer_id = main_table.referral_id AND o.store_id = main_table.store_id', array('cnt' => 'COUNT(main_table.invitation_id)')); return $this->getConnection()->fetchOne($select); }
function getDetailByJobId($jobid) { if ($this->isJobIdExists($jobid)) { $select = new Zend_Db_Select($this->db); $select->distinct(); switch ($this->db_adapter) { case 'PDO_MYSQL': $select->from(array('j' => 'Job'), array('JobId', 'Job', 'Name', 'Level', 'ClientId', 'StartTime' => "DATE_FORMAT(j.StartTime, '%y-%b-%d %H:%i')", 'EndTime' => "DATE_FORMAT(j.EndTime, '%y-%b-%d %H:%i')", 'SchedTime' => "DATE_FORMAT(j.SchedTime, '%y-%b-%d %H:%i')", 'VolSessionId', 'VolSessionTime', 'JobFiles', 'JobBytes', 'JobErrors', 'PoolId', 'FileSetId', 'PurgedFiles', 'JobStatus', 'Type', 'DurationTime' => 'TIMEDIFF(EndTime, StartTime)', 'PriorJobId', 'Reviewed', 'Comment')); $select->joinLeft(array('s' => 'Status'), 'j.JobStatus = s.JobStatus', array('JobStatusLong' => 'JobStatusLong')); break; case 'PDO_PGSQL': // PostgreSQL // http://www.postgresql.org/docs/8.0/static/functions-datetime.html $select->from(array('j' => 'Job'), array('JobId', 'Job', 'Name', 'Level', 'ClientId', 'StartTime', 'EndTime', 'SchedTime', 'VolSessionId', 'VolSessionTime', 'JobFiles', 'JobBytes', 'JobErrors', 'PoolId', 'FileSetId', 'PurgedFiles', 'JobStatus', 'Type', 'DurationTime' => '(EndTime - StartTime)', 'PriorJobId', 'Reviewed', 'Comment')); $select->joinLeft(array('s' => 'Status'), 'j.JobStatus = s.JobStatus', array('JobStatusLong' => 'JobStatusLong')); break; case 'PDO_SQLITE': // SQLite3 Documentation // http://sqlite.org/lang_datefunc.html // bug http://framework.zend.com/issues/browse/ZF-884 // http://sqlite.org/pragma.html //$res = $db->query('PRAGMA short_column_names=1'); // not affected //$res = $db->query('PRAGMA full_column_names=0'); // not affected $select->from(array('j' => 'Job'), array('jobid' => 'JobId', 'job' => 'Job', 'name' => 'Name', 'level' => 'Level', 'clientid' => 'ClientId', 'starttime' => 'StartTime', 'endtime' => 'EndTime', 'schedtime' => 'SchedTime', 'volsessionid' => 'VolSessionId', 'volsessiontime' => 'VolSessionTime', 'jobfiles' => 'JobFiles', 'jobbytes' => 'JobBytes', 'joberrors' => 'JobErrors', 'poolid' => 'PoolId', 'filesetid' => 'FileSetId', 'purgedfiles' => 'PurgedFiles', 'jobstatus' => 'JobStatus', 'type' => 'Type', 'DurationTime' => "(strftime('%H:%M:%S',strftime('%s',EndTime) - strftime('%s',StartTime),'unixepoch'))", 'priorjobid' => 'PriorJobId', 'reviewed' => 'Reviewed', 'comment' => 'Comment')); $select->joinLeft(array('s' => 'Status'), 'j.JobStatus = s.JobStatus', array('jobstatuslong' => 'JobStatusLong')); break; } $select->joinLeft(array('c' => 'Client'), 'j.ClientId = c.ClientId', array('ClientName' => 'Name', 'ClientUName' => 'UName')); $select->joinLeft(array('p' => 'Pool'), 'j.PoolId = p.PoolId', array('PoolName' => 'Name')); $select->joinLeft(array('f' => 'FileSet'), 'j.FileSetId = f.FileSetId', array('FileSetName' => 'FileSet', 'FileSetCreateTime' => 'CreateTime')); $select->joinLeft(array('sd' => 'webacula_jobdesc'), 'j.Name = sd.name_job'); $select->where("j.JobId = ?", $jobid); //$sql = $select->__toString(); echo "<pre>$sql</pre>"; exit; // for !!!debug!!! $stmt = $select->query(); $aresult['job'] = $stmt->fetchAll(); $select->reset(); unset($select); unset($stmt); // list volumes $select = new Zend_Db_Select($this->db); switch ($this->db_adapter) { case 'PDO_SQLITE': // bug http://framework.zend.com/issues/browse/ZF-884 $select->distinct(); $select->from(array('j' => 'JobMedia'), array('mediaid' => 'MediaId')); $select->joinInner(array('m' => 'Media'), 'j.MediaId = m.MediaId', array('volumename' => 'VolumeName')); $select->where("j.JobId = ?", $jobid); break; default: // mysql, postgresql $select->distinct(); $select->from(array('j' => 'JobMedia'), array('MediaId')); $select->joinInner(array('m' => 'Media'), 'j.MediaId = m.MediaId', array('VolumeName')); $select->where("j.JobId = ?", $jobid); } //$sql = $select->__toString(); echo "<pre>$sql</pre>"; exit; // for !!!debug!!! $stmt = $select->query(); $aresult['volume'] = $stmt->fetchAll(); $select->reset(); unset($select); unset($stmt); return $aresult; } }
/** * Padrão de Colunas para o relatório de Beneficiários * * @access protected * @param Zend_Db_Select $select * @return void */ protected function _columnsDefault(Zend_Db_Select $select) { $select->reset(Zend_Db_Select::COLUMNS); $select->columns(array('FEFOP_Contract.id_fefop_contract', 'FEFOP_Contract.num_district', 'FEFOP_Contract.num_program', 'FEFOP_Contract.num_module', 'AddDistrict.id_adddistrict', 'AddDistrict.District', 's.status_description', 'id_perdata' => 'b.id', 'b.code', 'b.name', 'target' => new Zend_Db_Expr("CASE WHEN b.target = 1 THEN 'Sin' ELSE 'Lae' END"), 'module' => new Zend_Db_Expr("CONCAT(FEFOP_Modules.acronym, ' - ', FEFOP_Modules.description)"), 'program' => new Zend_Db_Expr("CONCAT(FEFOP_Programs.acronym, ' - ', FEFOP_Programs.description)"), 'cod_contract' => new Zend_Db_Expr("CONCAT(FEFOP_Contract.num_program, '-', FEFOP_Contract.num_module, '-', FEFOP_Contract.num_district, '-', FEFOP_Contract.num_year, '-', FEFOP_Contract.num_sequence)"), 'disability' => new Zend_Db_Expr('(' . $this->_columnDisability() . ')'), 'gender' => new Zend_Db_Expr('(' . $this->_columnGender() . ')'), 'amount_contracted' => new Zend_Db_Expr('(' . $this->_columnAmountContracted() . ')'), 'amount_payment' => new Zend_Db_Expr('(' . $this->_columnAmouontPayment() . ')'), 'amount_real' => new Zend_Db_Expr('(' . $this->_columnAmountReal() . ')'), 'amount_addcosts' => new Zend_Db_Expr('(' . $this->_columnAdditional() . ')'))); $select->group(array('FEFOP_Contract.id_fefop_contract')); }
protected function _userProfileAlbums() { // // install content areas // $db = $this->getDb(); $select = new Zend_Db_Select($db); // profile page $select->from('engine4_core_pages')->where('name = ?', 'user_profile_index')->limit(1); $page_id = $select->query()->fetchObject()->page_id; // album.profile-albums // Check if it's already been placed $select = new Zend_Db_Select($db); $select->from('engine4_core_content')->where('page_id = ?', $page_id)->where('type = ?', 'widget')->where('name = ?', 'album.profile-albums'); $info = $select->query()->fetch(); if (empty($info)) { // container_id (will always be there) $select = new Zend_Db_Select($db); $select->from('engine4_core_content')->where('page_id = ?', $page_id)->where('type = ?', 'container')->limit(1); $container_id = $select->query()->fetchObject()->content_id; // middle_id (will always be there) $select = new Zend_Db_Select($db); $select->from('engine4_core_content')->where('parent_content_id = ?', $container_id)->where('type = ?', 'container')->where('name = ?', 'middle')->limit(1); $middle_id = $select->query()->fetchObject()->content_id; // tab_id (tab container) may not always be there $select->reset('where')->where('type = ?', 'widget')->where('name = ?', 'core.container-tabs')->where('page_id = ?', $page_id)->limit(1); $tab_id = $select->query()->fetchObject(); if ($tab_id && @$tab_id->content_id) { $tab_id = $tab_id->content_id; } else { $tab_id = null; } // tab on profile $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'album.profile-albums', 'parent_content_id' => $tab_id ? $tab_id : $middle_id, 'order' => 4, 'params' => '{"title":"Albums","titleCount":true}')); return $this; } }
function get() { $this->getApp(); $data = []; if ($this->auth->hasIdentity()) { $userinfo = $this->auth->getIdentity(); $ui = new \Mainsim_Model_UI(); $lastEdit = $ui->getLastUIEdited(); $sessionTs = empty($_SESSION['ui']) ? 0 : $_SESSION['ui']['ts']; if ($sessionTs < $lastEdit) { $_SESSION['ui']['data']['tabbars'] = $ui->getTabbars(); $_SESSION['ui']['data']['textfields'] = $ui->getTextfields(); $_SESSION['ui']['data']['picklists'] = $ui->getPicklists(); $_SESSION['ui']['data']['checkboxes'] = $ui->getCheckboxes(); $_SESSION['ui']['data']['menus'] = $ui->getMenus(); $_SESSION['ui']['data']['buttons'] = $ui->getButtons(); $_SESSION['ui']['data']['modules'] = $ui->getModules(); $_SESSION['ui']['data']['layouts'] = $ui->getLayouts(); $_SESSION['ui']['data']['selects'] = $ui->getSelects(); $_SESSION['ui']['data']['images'] = $ui->getImages(); $_SESSION['ui']['ts'] = time(); } $data = $_SESSION['ui']['data']; //BASEURL $data["global"] = array(); $data["global"]["delegates"] = array(); $weekStartsOn = 1; $data["global"]['weekStartsOn'] = $weekStartsOn; /** * Login data */ $data["global"]['online'] = $this->login->getOnlineNum(); $data["global"]['user'] = $this->getUserData($userinfo); /** * Constants not used by mainsim4 */ //$data["global"]['baseUrl'] = $this->view->baseUrl(); $data["global"]['imgDefaultPath'] = IMAGE_DEFAULT_PATH; $data["global"]['imgPath'] = IMAGE_PATH; $data["global"]['attachPath'] = ATTACHMENT_PATH; $data["global"]['libraryPath'] = LIBRARY_PATH; /** * Settings data */ $main = new \Mainsim_Model_Mainpage(); $settings = $main->getSettings(true); foreach ($settings as $k => $v) { $data["global"][$k] = \Mainsim_Model_Utilities::chg($v); } /** * Wo priorities */ $data["global"]["priorities"] = $main->getPriorities(); /** * Easter */ $data["global"]['easters'] = $main->getEasters(); /** * Localization */ $data["global"]["localization"] = $ui->getLocalization($userinfo->f_language); /** * Reverse Ajax Initialization */ $data["global"]["revajax"] = array("t_workorders" => array(), "t_wares" => array(), "t_selectors" => array(), "t_systems" => array()); $q = new \Zend_Db_Select(\Zend_Db::factory(\Zend_Registry::get('db'))); foreach ($data["global"]["revajax"] as $k => $v) { $q->from($k . "_types", array("f_id")); $res = $q->query()->fetchAll(); $q->reset(); foreach ($res as $r) { $data["global"]["revajax"][$k][$r["f_id"]] = array(); } } /** * Regular expressions */ $data["regexp"] = array("mail" => "/^(([^<>()[\\]\\\\.,;:\\s@\\\"] (\\.[^<>()[\\]\\\\.,;:\\s@\\\"] )*)|(\\ \". \\\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA -Z\\-0-9] \\.) [a-zA-Z]{2,}))\$/", "password" => "/^[a-zA-Z0-9\\@\\#\\-\\_\\.]{3,32}\$/", "username" => "/^[a-zA-Z0-9\\@\\#\\-\\_\\.]{3,32}\$/"); } return $data; }
/** * Public service for grouping treatment * * @param Zend_Db_Select $select */ public static function traitGroup(Zend_Db_Select $select) { // not needed for MySQL backends if ($select->getAdapter() instanceof Zend_Db_Adapter_Pdo_Mysql) { return; } $group = $select->getPart(Zend_Db_Select::GROUP); if (empty($group)) { return; } $columns = $select->getPart(Zend_Db_Select::COLUMNS); $updatedColumns = array(); //$column is an array where 0 is table, 1 is field and 2 is alias foreach ($columns as $key => $column) { if ($column[1] instanceof Zend_Db_Expr) { if (preg_match('/^\\(.*\\)/', $column[1])) { $updatedColumns[] = array($column[0], new Zend_Db_Expr("MIN(" . $column[1] . ")"), $column[2]); } else { $updatedColumns[] = $column; } continue; } if (preg_match('/^\\(.*\\)/', $column[1])) { $updatedColumns[] = array($column[0], new Zend_Db_Expr("MIN(" . $column[1] . ")"), $column[2]); continue; } // resolve * to single columns if ($column[1] == '*') { $tableFields = Tinebase_Db_Table::getTableDescriptionFromCache(SQL_TABLE_PREFIX . $column[0], $select->getAdapter()); foreach ($tableFields as $columnName => $schema) { // adds columns into group by clause (table.field) // checks if field has a function (that must be an aggregation) $fieldName = "{$column[0]}.{$columnName}"; if (in_array($fieldName, $group)) { $updatedColumns[] = array($column[0], $fieldName, $columnName); } else { // any selected field which is not in the group by clause must have an aggregate function // we choose MIN() as default. In practice the affected columns will have only one value anyways. $updatedColumns[] = array($column[0], new Zend_Db_Expr("MIN(" . $select->getAdapter()->quoteIdentifier($fieldName) . ")"), $columnName); } } continue; } $fieldName = $column[0] . '.' . $column[1]; if (in_array($fieldName, $group)) { $updatedColumns[] = $column; } else { // any selected field which is not in the group by clause must have an aggregate function // we choose MIN() as default. In practice the affected columns will have only one value anyways. $updatedColumns[] = array($column[0], new Zend_Db_Expr("MIN(" . $select->getAdapter()->quoteIdentifier($fieldName) . ")"), $column[2] ? $column[2] : $column[1]); } } $select->reset(Zend_Db_Select::COLUMNS); foreach ($updatedColumns as $column) { $select->columns(!empty($column[2]) ? array($column[2] => $column[1]) : $column[1], $column[0]); } // add order by columns to group by $order = $select->getPart(Zend_Db_Select::ORDER); foreach ($order as $column) { $field = $column[0]; if (preg_match('/.*\\..*/', $field) && !in_array($field, $group)) { // adds column into group by clause (table.field) $group[] = $field; } } $select->reset(Zend_Db_Select::GROUP); $select->group($group); }
/** * Put data from DB to 2D array * * @param integer $y - year - YYYY * @param integer $m - month * @param integer $d - day * @return array 2D */ public function getDataTimeline($date) { if (!empty($date)) { $db = Zend_Db_Table::getDefaultAdapter(); // ********** query 1 ******************* $select = new Zend_Db_Select($db); $select->distinct(); switch ($this->db_adapter) { case 'PDO_MYSQL': // http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format // %H - Hour (00..23) // %i - Minutes, numeric (00..59) $select->from('Job', array('JobId', 'Name', 'StartTime', 'EndTime', 'JobErrors', 'JobStatus', 'h1' => "DATE_FORMAT(StartTime, '%H')", 'm1' => "DATE_FORMAT(StartTime, '%i')", 'h2' => "DATE_FORMAT(EndTime, '%H')", 'm2' => "DATE_FORMAT(EndTime, '%i')")); break; case 'PDO_PGSQL': // PostgreSQL // http://www.postgresql.org/docs/8.0/static/functions-formatting.html // HH24 - hour of day (00-23) // MI - minute (00-59) $select->from('Job', array('JobId', 'Name', 'StartTime', 'EndTime', 'JobErrors', 'JobStatus', 'h1' => "to_char(StartTime, 'HH24')", 'm1' => "to_char(StartTime, 'MI')", 'h2' => "to_char(EndTime, 'HH24')", 'm2' => "to_char(EndTime, 'MI')")); break; case 'PDO_SQLITE': // SQLite3 Documentation // http://sqlite.org/lang_datefunc.html // %H - Hour (00 .. 23) // %M - Minute (00 .. 59) // bug http://framework.zend.com/issues/browse/ZF-884 $select->from('Job', array('jobid' => 'JobId', 'name' => 'Name', 'starttime' => 'StartTime', 'endtime' => 'EndTime', 'joberrors' => 'JobErrors', 'jobstatus' => 'JobStatus', 'h1' => "(strftime('%H',StartTime))", 'm1' => "(strftime('%M',StartTime))", 'h2' => "(strftime('%H',EndTime))", 'm2' => "(strftime('%M',EndTime))")); break; } $select->joinLeft(array('sd' => 'webacula_jobdesc'), 'Job.Name = sd.name_job'); $select->where("(StartTime >= '{$date} 00:00:00') AND (StartTime <= '{$date} 23:59:59') AND\n (EndTime <= '{$date} 23:59:59')"); $select->order('JobId'); //$sql = $select->__toString(); echo "<pre>$sql</pre>"; exit; // for !!!debug!!! $stmt = $select->query(); $result = $stmt->fetchAll(); // забиваем результат в массив $i = 0; foreach ($result as $line) { $this->atime[$i]['jobid'] = $line['jobid']; $this->atime[$i]['name'] = $line['name']; $this->atime[$i]['short_desc'] = $line['short_desc']; $this->atime[$i]['h1'] = $line['h1'] + $line['m1'] / 60; $this->atime[$i]['h2'] = $line['h2'] + $line['m2'] / 60; $this->atime[$i]['flag'] = 0; // признак, что задание уложилось в сутки $this->atime[$i]['start'] = $line['starttime']; $this->atime[$i]['end'] = $line['endtime']; $i++; } $select->reset(); unset($select); unset($stmt); // задания, старт или окончание которых лежат за пределами указанных суток // задание началось ранее // либо задание еще длится // ********** query 2 ******************* $select = new Zend_Db_Select($db); $select->distinct(); switch ($this->db_adapter) { case 'PDO_MYSQL': // http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format // %H - Hour (00..23) // %i - Minutes, numeric (00..59) $select->from('Job', array('JobId', 'Name', 'StartTime', 'EndTime', 'JobErrors', 'JobStatus', 'h1' => "DATE_FORMAT(StartTime, '%H')", 'm1' => "DATE_FORMAT(StartTime, '%i')", 'h2' => "DATE_FORMAT(EndTime, '%H')", 'm2' => "DATE_FORMAT(EndTime, '%i')")); break; case 'PDO_PGSQL': // PostgreSQL // http://www.postgresql.org/docs/8.0/static/functions-formatting.html // HH24 - hour of day (00-23) // MI - minute (00-59) $select->from('Job', array('JobId', 'Name', 'StartTime', 'EndTime', 'JobErrors', 'JobStatus', 'h1' => "to_char(StartTime, 'HH24')", 'm1' => "to_char(StartTime, 'MI')", 'h2' => "to_char(EndTime, 'HH24')", 'm2' => "to_char(EndTime, 'MI')")); break; case 'PDO_SQLITE': // SQLite3 Documentation // http://sqlite.org/lang_datefunc.html // %H - Hour (00 .. 23) // %M - Minute (00 .. 59) // bug http://framework.zend.com/issues/browse/ZF-884 $select->from('Job', array('jobid' => 'JobId', 'name' => 'Name', 'starttime' => 'StartTime', 'endtime' => 'EndTime', 'joberrors' => 'JobErrors', 'jobstatus' => 'JobStatus', 'h1' => "(strftime('%H',StartTime))", 'm1' => "(strftime('%M',StartTime))", 'h2' => "(strftime('%H',EndTime))", 'm2' => "(strftime('%M',EndTime))")); break; } $select->joinLeft(array('sd' => 'webacula_jobdesc'), 'Job.Name = sd.name_job'); $select->where("( \n (EndTime > '{$date} 00:00:00') AND \n ( \n (EndTime <= '{$date} 23:59:59') OR \n ( \n (EndTime IS NULL) AND \n (Job.jobstatus IN ('R', 'B', 'A', 'F', 'S', 'm', 'M', 's', 'j', 'c', 'd', 't', 'p', 'i', 'a', 'l', 'L') ) \n ) \n ) \n )\n AND\n (StartTime < '{$date} 00:00:00')"); $select->order('JobId'); //$sql = $select->__toString(); echo "<pre>$sql</pre>"; exit; // for !!!debug!!! $stmt = $select->query(); $result = $stmt->fetchAll(); // забиваем результат в массив foreach ($result as $line) { $this->atime[$i]['jobid'] = $line['jobid']; $this->atime[$i]['name'] = $line['name']; $this->atime[$i]['short_desc'] = $line['short_desc']; $this->atime[$i]['h1'] = 0; $this->atime[$i]['h2'] = $line['h2'] + $line['m2'] / 60; $this->atime[$i]['flag'] = -1; // признак, что задание началось ранее $this->atime[$i]['start'] = $line['starttime']; $this->atime[$i]['end'] = $line['endtime']; $i++; } $select->reset(); unset($select); unset($stmt); // задание закончилось позднее // либо задание еще длится // ********** query 3 ******************* $select = new Zend_Db_Select($db); $select->distinct(); switch ($this->db_adapter) { case 'PDO_MYSQL': // http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format // %H - Hour (00..23) // %i - Minutes, numeric (00..59) $select->from('Job', array('JobId', 'Name', 'StartTime', 'EndTime', 'JobErrors', 'JobStatus', 'h1' => "DATE_FORMAT(StartTime, '%H')", 'm1' => "DATE_FORMAT(StartTime, '%i')", 'h2' => "DATE_FORMAT(EndTime, '%H')", 'm2' => "DATE_FORMAT(EndTime, '%i')")); break; case 'PDO_PGSQL': // PostgreSQL // http://www.postgresql.org/docs/8.0/static/functions-formatting.html // HH24 - hour of day (00-23) // MI - minute (00-59) $select->from('Job', array('JobId', 'Name', 'StartTime', 'EndTime', 'JobErrors', 'JobStatus', 'h1' => "to_char(StartTime, 'HH24')", 'm1' => "to_char(StartTime, 'MI')", 'h2' => "to_char(EndTime, 'HH24')", 'm2' => "to_char(EndTime, 'MI')")); break; case 'PDO_SQLITE': // SQLite3 Documentation // http://sqlite.org/lang_datefunc.html // %H - Hour (00 .. 23) // %M - Minute (00 .. 59) // bug http://framework.zend.com/issues/browse/ZF-884 $select->from('Job', array('jobid' => 'JobId', 'name' => 'Name', 'starttime' => 'StartTime', 'endtime' => 'EndTime', 'joberrors' => 'JobErrors', 'jobstatus' => 'JobStatus', 'h1' => "(strftime('%H',StartTime))", 'm1' => "(strftime('%M',StartTime))", 'h2' => "(strftime('%H',EndTime))", 'm2' => "(strftime('%M',EndTime))")); } $select->joinLeft(array('sd' => 'webacula_jobdesc'), 'Job.Name = sd.name_job'); $select->where("( \n (StartTime >= '{$date} 00:00:00') AND (StartTime <= '{$date} 23:59:59') \n ) AND\n\t\t\t\t( \n (EndTime > '{$date} 23:59:59') OR \n (\n (EndTime IS NULL) AND\n (Job.jobstatus IN ('R', 'B', 'A', 'F', 'S', 'm', 'M', 's', 'j', 'c', 'd', 't', 'p', 'i', 'a', 'l', 'L') )\n )\n )"); $select->order('JobId'); //$sql = $select->__toString(); echo "<pre>$sql</pre>"; exit; // for !!!debug!!! $stmt = $select->query(); $result = $stmt->fetchAll(); // забиваем результат в массив foreach ($result as $line) { $this->atime[$i]['jobid'] = $line['jobid']; $this->atime[$i]['name'] = $line['name']; $this->atime[$i]['short_desc'] = $line['short_desc']; $this->atime[$i]['h1'] = $line['h1'] + $line['m1'] / 60; $this->atime[$i]['h2'] = 23.9; $this->atime[$i]['flag'] = 1; // признак, что задание окончилось позднее $this->atime[$i]['start'] = $line['starttime']; $this->atime[$i]['end'] = $line['endtime']; $i++; } $select->reset(); unset($select); unset($stmt); // задание началось ранее и закончилось позднее (очень длинное задание) // либо задание еще длится // ********** query 4 ******************* $select = new Zend_Db_Select($db); $select->distinct(); switch ($this->db_adapter) { case 'PDO_MYSQL': // http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format // %H - Hour (00..23) // %i - Minutes, numeric (00..59) $select->from('Job', array('JobId', 'Name', 'StartTime', 'EndTime', 'JobErrors', 'JobStatus', 'h1' => "DATE_FORMAT(StartTime, '%H')", 'm1' => "DATE_FORMAT(StartTime, '%i')", "h2" => "DATE_FORMAT(EndTime, '%H')", 'm2' => "DATE_FORMAT(EndTime, '%i')")); break; case 'PDO_PGSQL': // PostgreSQL // http://www.postgresql.org/docs/8.0/static/functions-formatting.html // HH24 - hour of day (00-23) // MI - minute (00-59) $select->from('Job', array('JobId', 'Name', 'StartTime', 'EndTime', 'JobErrors', 'JobStatus', 'h1' => "to_char(StartTime, 'HH24')", 'm1' => "to_char(StartTime, 'MI')", "h2" => "to_char(EndTime, 'HH24')", 'm2' => "to_char(EndTime, 'MI')")); break; case 'PDO_SQLITE': // SQLite3 Documentation // http://sqlite.org/lang_datefunc.html // %H - Hour (00 .. 23) // %M - Minute (00 .. 59) // bug http://framework.zend.com/issues/browse/ZF-884 $select->from('Job', array('jobid' => 'JobId', 'name' => 'Name', 'starttime' => 'StartTime', 'endtime' => 'EndTime', 'joberrors' => 'JobErrors', 'jobstatus' => 'JobStatus', 'h1' => "(strftime('%H',StartTime))", 'm1' => "(strftime('%M',StartTime))", 'h2' => "(strftime('%H',EndTime))", 'm2' => "(strftime('%M',EndTime))")); break; } $select->joinLeft(array('sd' => 'webacula_jobdesc'), 'Job.Name = sd.name_job'); $select->where("(StartTime < '{$date} 00:00:00') AND \n ( \n (EndTime > '{$date} 23:59:59') OR \n (\n (EndTime IS NULL) AND\n (Job.jobstatus IN ('R', 'B', 'A', 'F', 'S', 'm', 'M', 's', 'j', 'c', 'd', 't', 'p', 'i', 'a', 'l', 'L') )\n )\n )"); $select->order('JobId'); //$sql = $select->__toString(); echo "<pre>$sql</pre>"; exit; // for !!!debug!!! $stmt = $select->query(); $result = $stmt->fetchAll(); // забиваем результат в массив foreach ($result as $line) { $this->atime[$i]['jobid'] = $line['jobid']; $this->atime[$i]['name'] = $line['name']; $this->atime[$i]['short_desc'] = $line['short_desc']; $this->atime[$i]['h1'] = 0; $this->atime[$i]['h2'] = 23.9; $this->atime[$i]['flag'] = 2; // признак, что задание началось ранее и окончилось позднее (очень длинное задание) $this->atime[$i]['start'] = $line['starttime']; $this->atime[$i]['end'] = $line['endtime']; $i++; } $select->reset(); unset($select); unset($stmt); // do Bacula ACLs $this->atime = $this->bacula_acl->doBaculaAcl($this->atime, 'name', 'job'); } }
/** * Retreive product count select for categories * * @return Varien_Db_Select */ public function getProductCountSelect() { if ($this->_productCountSelect === null) { $this->_productCountSelect = clone $this->getSelect(); $this->_productCountSelect->reset(Zend_Db_Select::COLUMNS)->reset(Zend_Db_Select::GROUP)->reset(Zend_Db_Select::ORDER)->distinct(false)->join(array('count_table' => $this->getTable('catalog_category_product_index')), 'count_table.product_id = e.entity_id', array('count_table.category_id', 'product_count' => new Zend_Db_Expr('COUNT(DISTINCT count_table.product_id)')))->where('count_table.store_id = ?', $this->getStoreId())->group('count_table.category_id'); } return $this->_productCountSelect; }
function onInstall() { $this->_albumCreatePage(); $this->_albumManagePage(); $this->_albumViewPage(); $this->_virtualAlbumCreatePage(); // // install content areas // $db = $this->getDb(); $select = new Zend_Db_Select($db); // profile page $select->from('engine4_core_pages')->where('name = ?', 'user_profile_index')->limit(1); $page_id = $select->query()->fetchObject()->page_id; // album.profile-albums // Check if it's already been placed $select = new Zend_Db_Select($db); $select->from('engine4_core_content')->where('page_id = ?', $page_id)->where('type = ?', 'widget')->where('name = ?', 'advalbum.profile-albums'); $info = $select->query()->fetch(); if (empty($info)) { // container_id (will always be there) $select = new Zend_Db_Select($db); $select->from('engine4_core_content')->where('page_id = ?', $page_id)->where('type = ?', 'container')->limit(1); $container_id = $select->query()->fetchObject()->content_id; // middle_id (will always be there) $select = new Zend_Db_Select($db); $select->from('engine4_core_content')->where('parent_content_id = ?', $container_id)->where('type = ?', 'container')->where('name = ?', 'middle')->limit(1); $middle_id = $select->query()->fetchObject()->content_id; // tab_id (tab container) may not always be there $select->reset('where')->where('type = ?', 'widget')->where('name = ?', 'core.container-tabs')->where('page_id = ?', $page_id)->limit(1); $tab_id = $select->query()->fetchObject(); if ($tab_id && @$tab_id->content_id) { $tab_id = $tab_id->content_id; } else { $tab_id = null; } // tab on profile $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.profile-albums', 'parent_content_id' => $tab_id ? $tab_id : $middle_id, 'order' => 4, 'params' => '{"title":"Albums","titleCount":true}')); } // update album home page $select = new Zend_Db_Select($db); $select->from('engine4_core_pages')->where('name = ?', 'advalbum_index_browse')->limit(1); $info = $select->query()->fetch(); $page_id = 0; if ($info) { $page_id = $info['page_id']; } $select = new Zend_Db_Select($db); $select->from('engine4_core_content')->where('name = ?', 'advalbum.top-recent-albums')->where('page_id = ?', $page_id)->limit(1); $info = $select->query()->fetch(); if ($info) { $order = $info['order']; $parent_content_id = $info['parent_content_id']; try { $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'core.container-tabs', 'parent_content_id' => $parent_content_id, 'order' => $order, 'params' => '{"max":"6","title":"","name":"core.container-tabs"}')); $tab_id = $db->lastInsertId('engine4_core_content'); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.top-albums', 'parent_content_id' => $tab_id, 'order' => 1, 'params' => '{"title":"Top Albums"}')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.recent-albums', 'parent_content_id' => $tab_id, 'order' => 2, 'params' => '{"title":"Recent Ablums"}')); } catch (Exception $e) { } } // Browse Album $select = new Zend_Db_Select($db); $select->from('engine4_core_pages')->where('name = ?', 'advalbum_index_browse')->limit(1); $info = $select->query()->fetch(); if (empty($info)) { $db->insert('engine4_core_pages', array('name' => 'advalbum_index_browse', 'displayname' => 'Advanced Albums Homepage', 'title' => 'Browse Albums', 'description' => 'This is browse albums page.')); $page_id = $db->lastInsertId('engine4_core_pages'); // containers $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'container', 'name' => 'top', 'parent_content_id' => null, 'order' => 1, 'params' => '')); $top_id = $db->lastInsertId('engine4_core_content'); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'container', 'name' => 'middle', 'parent_content_id' => $top_id, 'order' => 6, 'params' => '')); $middle_id = $db->lastInsertId('engine4_core_content'); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.albums-menu', 'parent_content_id' => $middle_id, 'order' => 3, 'params' => '')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'container', 'name' => 'main', 'parent_content_id' => null, 'order' => 2, 'params' => '')); $container_id = $db->lastInsertId('engine4_core_content'); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'container', 'name' => 'middle', 'parent_content_id' => $container_id, 'order' => 6, 'params' => '')); $middle_id = $db->lastInsertId('engine4_core_content'); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'container', 'name' => 'right', 'parent_content_id' => $container_id, 'order' => 5, 'params' => '')); $right_id = $db->lastInsertId('engine4_core_content'); // middle column $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'core.container-tabs', 'parent_content_id' => $middle_id, 'order' => 1, 'params' => '{"max":"6","title":"","name":"core.container-tabs"}')); $tab0_id = $db->lastInsertId('engine4_core_content'); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.featured-photos', 'parent_content_id' => $tab0_id, 'order' => 1, 'params' => '{"title":"Featured Photos"}')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.featured-albums', 'parent_content_id' => $middle_id, 'order' => 6, 'params' => '{"title":"Featured Albums"}')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.top-recent-albums', 'parent_content_id' => $middle_id, 'order' => 7, 'params' => '{"title":""}')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'core.container-tabs', 'parent_content_id' => $middle_id, 'order' => 8, 'params' => '{"max":"6","title":"","name":"core.container-tabs"}')); $tab11_id = $db->lastInsertId('engine4_core_content'); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.top-albums', 'parent_content_id' => $tab11_id, 'order' => 1, 'params' => '{"title":"Top Albums"}')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.recent-albums', 'parent_content_id' => $tab11_id, 'order' => 2, 'params' => '{"title":"Recent Albums"}')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'core.container-tabs', 'parent_content_id' => $middle_id, 'order' => 9, 'params' => '{"max":"6","title":"","name":"core.container-tabs"}')); $tab1_id = $db->lastInsertId('engine4_core_content'); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.recent-photos', 'parent_content_id' => $tab1_id, 'order' => 1, 'params' => '{"title":"Recent Photos"}')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.most-viewed-photos', 'parent_content_id' => $tab1_id, 'order' => 2, 'params' => '{"title":"Most Viewed Photos"}')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.most-commented-photos', 'parent_content_id' => $tab1_id, 'order' => 3, 'params' => '{"title":"Most Commented Photos"}')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'core.container-tabs', 'parent_content_id' => $middle_id, 'order' => 10, 'params' => '{"max":"6"}')); $tab2_id = $db->lastInsertId('engine4_core_content'); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.this-month-photos', 'parent_content_id' => $tab2_id, 'order' => 1, 'params' => '{"title":"This Month\'s Photos"}')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.this-week-photos', 'parent_content_id' => $tab2_id, 'order' => 2, 'params' => '{"title":"This Week\'s Photos"}')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.today-photos', 'parent_content_id' => $tab2_id, 'order' => 3, 'params' => '{"title":"Today\'s Photos"}')); // right column $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.albums-search', 'parent_content_id' => $right_id, 'order' => 17, 'params' => '')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.albums-categories', 'parent_content_id' => $right_id, 'order' => 18, 'params' => '{"title":"Categories"}')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.albums-top-members', 'parent_content_id' => $right_id, 'order' => 19, 'params' => '{"title":"Top Members"}')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.albums-statistics', 'parent_content_id' => $right_id, 'order' => 20, 'params' => '{"title":"Statistics"}')); } // Listing Album $select = new Zend_Db_Select($db); $select->from('engine4_core_pages')->where('name = ?', 'advalbum_index_listing')->limit(1); $info = $select->query()->fetch(); if (empty($info)) { $db->insert('engine4_core_pages', array('name' => 'advalbum_index_listing', 'displayname' => 'Advanced Albums Listing', 'title' => 'Albums Listing', 'description' => 'This is albums listing page.')); $page_id = $db->lastInsertId('engine4_core_pages'); // containers $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'container', 'name' => 'top', 'parent_content_id' => null, 'order' => 1, 'params' => '')); $top_id = $db->lastInsertId('engine4_core_content'); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'container', 'name' => 'middle', 'parent_content_id' => $top_id, 'order' => 6, 'params' => '')); $middle_id = $db->lastInsertId('engine4_core_content'); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.albums-menu', 'parent_content_id' => $middle_id, 'order' => 3, 'params' => '')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'container', 'name' => 'main', 'parent_content_id' => null, 'order' => 2, 'params' => '')); $container_id = $db->lastInsertId('engine4_core_content'); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'container', 'name' => 'middle', 'parent_content_id' => $container_id, 'order' => 6, 'params' => '')); $middle_id = $db->lastInsertId('engine4_core_content'); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'container', 'name' => 'right', 'parent_content_id' => $container_id, 'order' => 5, 'params' => '')); $right_id = $db->lastInsertId('engine4_core_content'); // middle column $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.albums-listing', 'parent_content_id' => $middle_id, 'order' => 6, 'params' => '')); // right column $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.albums-search', 'parent_content_id' => $right_id, 'order' => 17, 'params' => '')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.albums-categories', 'parent_content_id' => $right_id, 'order' => 18, 'params' => '{"title":"Categories"}')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.albums-top-members', 'parent_content_id' => $right_id, 'order' => 19, 'params' => '{"title":"Top Members"}')); } // Listing Photo $select = new Zend_Db_Select($db); $select->from('engine4_core_pages')->where('name = ?', 'advalbum_index_listing-photo')->limit(1); $info = $select->query()->fetch(); if (empty($info)) { $db->insert('engine4_core_pages', array('name' => 'advalbum_index_listing-photo', 'displayname' => 'Advanced Albums Listing Photos', 'title' => 'Photos Listing', 'description' => 'This is photos listing page.')); $page_id = $db->lastInsertId('engine4_core_pages'); // containers $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'container', 'name' => 'top', 'parent_content_id' => null, 'order' => 1, 'params' => '')); $top_id = $db->lastInsertId('engine4_core_content'); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'container', 'name' => 'middle', 'parent_content_id' => $top_id, 'order' => 6, 'params' => '')); $middle_id = $db->lastInsertId('engine4_core_content'); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.albums-menu', 'parent_content_id' => $middle_id, 'order' => 3, 'params' => '')); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'container', 'name' => 'main', 'parent_content_id' => null, 'order' => 2, 'params' => '')); $container_id = $db->lastInsertId('engine4_core_content'); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'container', 'name' => 'middle', 'parent_content_id' => $container_id, 'order' => 6, 'params' => '')); $middle_id = $db->lastInsertId('engine4_core_content'); $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'container', 'name' => 'right', 'parent_content_id' => $container_id, 'order' => 5, 'params' => '')); $right_id = $db->lastInsertId('engine4_core_content'); // middle column $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.photos-listing', 'parent_content_id' => $middle_id, 'order' => 6, 'params' => '')); // right column $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'advalbum.photos-search', 'parent_content_id' => $right_id, 'order' => 17, 'params' => '')); } if ($this->checkModuleAlbum()) { $db = $this->getDb(); $db->query("UPDATE `engine4_core_modules` SET `enabled`= 0 WHERE `engine4_core_modules`.`name` = 'album';"); // delete duplicate album row from engine4_authorization_allow $query = "select * FROM `engine4_authorization_allow` AS a1 Where a1.resource_type = 'album' AND EXISTS (\n SELECT * FROM `engine4_authorization_allow` a2\n WHERE a2.resource_type = 'advalbum_album'\n AND a1.resource_id = a2.resource_id\n AND a1.`action` = a2.`action`\n AND a1.role = a2.role\n AND a1.role_id = a2.role_id)"; $this->deleteDuplicateAlbumPermissionRow($query); $this->updateAlbumsConfiguration("1"); /* try { $db->query( "ALTER TABLE `engine4_album_photos` ADD COLUMN `order` int(11) unsigned NOT NULL default '0' AFTER `modified_date`;"); } catch (exception $e) {} try { $db->query("ALTER TABLE `engine4_album_albums` ADD COLUMN `rating` FLOAT NOT NULL DEFAULT '0'"); } catch (exception $e) {} try { $db->query("ALTER TABLE `engine4_album_albums` ADD COLUMN `featured` TINYINT(1) NULL DEFAULT '0'"); } catch (exception $e) {} */ } try { $db->query("ALTER TABLE `engine4_album_photos` ADD COLUMN `order` int(11) unsigned NOT NULL default '0' AFTER `modified_date`;"); } catch (exception $e) { } // hide the previous versions of YouNetCore's Adv Albums try { $this->renamePreviousVersion(); } catch (exception $e) { } parent::onInstall(); }