/** * The code that needs to be called when the cron is running * * @param GO\Base\Cron\CronJob $cronJob * @param GO\Base\Model\User $user */ public function run(GO\Base\Cron\CronJob $cronJob, GO\Base\Model\User $user = null) { $filesStmt = File::model()->find(FindParams::newInstance()->ignoreAcl()->criteria(FindCriteria::newInstance()->addCondition('expire_time', time(), '<')->addCondition('expire_time', '0', '>')->addCondition('random_code', '', '!=')->addCondition('delete_when_expired', '1'))); foreach ($filesStmt as $fileModel) { $fileModel->delete(); } }
/** * Get the table rows that need to be printed in the pdf * * @return array */ public function getRows() { if (empty($this->_rows)) { foreach ($this->calendars as $calendar) { $row = array('name' => $calendar->name); // foreach($this->categories as $category){ $findParams = \GO\Base\Db\FindParams::newInstance()->ignoreAcl()->select('COUNT(*) as count, category_id')->group('category_id'); // $findParams->ignoreAcl(); // Only count items that are visible for this user. // $findParams->group('calendar_id'); $findCriteria = \GO\Base\Db\FindCriteria::newInstance(); $findCriteria->addCondition('calendar_id', $calendar->id); $findCriteria->addCondition('start_time', strtotime($this->startDate), '>'); $findCriteria->addCondition('end_time', strtotime($this->endDate), '<'); $findParams->criteria($findCriteria); $catRecord = array(); foreach (Event::model()->find($findParams) as $record) { $catRecord[intval($record->category_id)] = $record->count; } foreach ($this->categories as $category) { $row[] = isset($catRecord[$category->id]) ? $catRecord[$category->id] : 0; } $this->_rows[] = $row; } // } } return $this->_rows; }
/** * processStoreDelete * * @param $store * @param $params */ protected function processStoreDelete($store, &$params) { if (isset($params['delete_keys'])) { $deleteRecords = json_decode($params['delete_keys'], true); $deleteRecords = array_filter($deleteRecords, 'intval'); $criteria = FindCriteria::newInstance(); $criteria->addCondition('default', 0); $criteria->addInCondition('id', $deleteRecords); $findParams = FindParams::newInstance()->criteria($criteria); $stmt = Label::model()->find($findParams); $deleteRecords = array(); while ($label = $stmt->fetch()) { $deleteRecords[] = $label->getPk(); } if (!count($deleteRecords)) { $params['delete_keys'] = '[]'; } else { $params['delete_keys'] = json_encode($deleteRecords); } } $store->processDeleteActions($params, $this->model); if (isset($params['delete_keys']) && !count($params['delete_keys'])) { $store->response['deleteSuccess'] = true; } }
/** * The code that needs to be called when the cron is running * * If $this->enableUserAndGroupSupport() returns TRUE then the run function * will be called for each $user. (The $user parameter will be given) * * If $this->enableUserAndGroupSupport() returns FALSE then the * $user parameter is null and the run function will be called only once. * * @param CronJob $cronJob * @param \GO\Base\Model\User $user [OPTIONAL] */ public function run(CronJob $cronJob, \GO\Base\Model\User $user = null) { \GO::session()->runAsRoot(); $usersStmt = \GO\Base\Model\User::model()->findByAttribute('mail_reminders', 1); while ($userModel = $usersStmt->fetch()) { \GO::debug("Sending mail reminders to " . $userModel->username); $remindersStmt = \GO\Base\Model\Reminder::model()->find(\GO\Base\Db\FindParams::newInstance()->joinModel(array('model' => 'GO\\Base\\Model\\ReminderUser', 'localTableAlias' => 't', 'localField' => 'id', 'foreignField' => 'reminder_id', 'tableAlias' => 'ru'))->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('user_id', $userModel->id, '=', 'ru')->addCondition('time', time(), '<', 'ru')->addCondition('mail_sent', '0', '=', 'ru'))); while ($reminderModel = $remindersStmt->fetch()) { // $relatedModel = $reminderModel->getRelatedModel(); // var_dump($relatedModel->name); // $modelName = $relatedModel ? $relatedModel->localizedName : \GO::t('unknown'); $subject = \GO::t('reminder') . ': ' . $reminderModel->name; $time = !empty($reminderModel->vtime) ? $reminderModel->vtime : $reminderModel->time; date_default_timezone_set($userModel->timezone); $body = \GO::t('time') . ': ' . date($userModel->completeDateFormat . ' ' . $userModel->time_format, $time) . "\n"; $body .= \GO::t('name') . ': ' . str_replace('<br />', ',', $reminderModel->name) . "\n"; // date_default_timezone_set(\GO::user()->timezone); $message = \GO\Base\Mail\Message::newInstance($subject, $body); $message->addFrom(\GO::config()->noreply_email, \GO::config()->title); $message->addTo($userModel->email, $userModel->name); \GO\Base\Mail\Mailer::newGoInstance()->send($message, $failedRecipients); if (!empty($failedRecipients)) { trigger_error("Reminder mail failed for recipient: " . implode(',', $failedRecipients), E_USER_NOTICE); } $reminderUserModelSend = \GO\Base\Model\ReminderUser::model()->findSingleByAttributes(array('user_id' => $userModel->id, 'reminder_id' => $reminderModel->id)); $reminderUserModelSend->mail_sent = 1; $reminderUserModelSend->save(); } date_default_timezone_set(\GO::user()->timezone); } }
public static function checkIpAddress(array &$params, array &$response) { $oldIgnoreAcl = \GO::setIgnoreAclPermissions(); $userModel = \GO\Base\Model\User::model()->findSingleByAttribute('username', $params['username']); if (!$userModel) { return true; } $allowedIpAddresses = array(); //"127.0.0.1"); $whitelistIpAddressesStmt = Model\IpAddress::model()->find(\GO\Base\Db\FindParams::newInstance()->select('t.ip_address')->joinModel(array('model' => 'GO\\Ipwhitelist\\Model\\EnableWhitelist', 'localTableAlias' => 't', 'localField' => 'group_id', 'foreignField' => 'group_id', 'tableAlias' => 'ew', 'type' => 'INNER'))->joinModel(array('model' => 'GO\\Base\\Model\\UserGroup', 'localTableAlias' => 'ew', 'localField' => 'group_id', 'foreignField' => 'group_id', 'tableAlias' => 'usergroup', 'type' => 'INNER'))->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('user_id', $userModel->id, '=', 'usergroup'))); if (!empty($whitelistIpAddressesStmt) && $whitelistIpAddressesStmt->rowCount() > 0) { foreach ($whitelistIpAddressesStmt as $ipAddressModel) { // $enabledWhitelistModel = Model\EnableWhitelist::model()->findByPk($groupModel->id); // if (!empty($enabledWhitelistModel)) { // $ipAddressesStmt = Model\IpAddress::model()->findByAttribute('group_id',$groupModel->id); // foreach ($ipAddressesStmt as $ipAddressModel) { if (!in_array($ipAddressModel->ip_address, $allowedIpAddresses)) { $allowedIpAddresses[] = $ipAddressModel->ip_address; } // } // } } } \GO::setIgnoreAclPermissions($oldIgnoreAcl); if (count($allowedIpAddresses) > 0 && !in_array($_SERVER['REMOTE_ADDR'], $allowedIpAddresses)) { $response['feedback'] = sprintf(\GO::t('wrongLocation', 'ipwhitelist'), $_SERVER['REMOTE_ADDR']); $response['success'] = false; return false; } return true; }
/** * Get the data for the grid that shows all the tasks from the selected tasklists. * * @param Array $params * @return Array The array with the data for the grid. */ protected function actionBirthdays($params) { $today = mktime(0, 0, 0); $next_month = \GO\Base\Util\Date::date_add(mktime(0, 0, 0), 30); //\GO::debug($yesterday); $start = date('Y-m-d', $today); $end = date('Y-m-d', $next_month); //\GO::debug($start); $select = "t.id, birthday, first_name, middle_name, last_name, addressbook_id, photo, " . "IF (STR_TO_DATE(CONCAT(YEAR('{$start}'),'/',MONTH(birthday),'/',DAY(birthday)),'%Y/%c/%e') >= '{$start}', " . "STR_TO_DATE(CONCAT(YEAR('{$start}'),'/',MONTH(birthday),'/',DAY(birthday)),'%Y/%c/%e') , " . "STR_TO_DATE(CONCAT(YEAR('{$start}')+1,'/',MONTH(birthday),'/',DAY(birthday)),'%Y/%c/%e')) " . "as upcoming "; $findCriteria = \GO\Base\Db\FindCriteria::newInstance()->addCondition('birthday', '0000-00-00', '!=')->addRawCondition('birthday', 'NULL', 'IS NOT'); $settings = \GO\Addressbook\Model\BirthdaysPortletSetting::model()->findByAttribute('user_id', \GO::user()->id); if (count($settings)) { $abooks = array_map(function ($value) { return $value->addressbook_id; }, $settings->fetchAll()); $findCriteria->addInCondition('addressbook_id', $abooks); } $having = "upcoming BETWEEN '{$start}' AND '{$end}'"; $findParams = \GO\Base\Db\FindParams::newInstance()->distinct()->select($select)->criteria($findCriteria)->having($having)->order('upcoming'); //$response['data']['original_photo_url']=$model->photoURL; $columnModel = new \GO\Base\Data\ColumnModel('GO\\Addressbook\\Model\\Contact'); $columnModel->formatColumn('addressbook_id', '$model->addressbook->name'); $columnModel->formatColumn('photo_url', '$model->getPhotoThumbURL()'); $columnModel->formatColumn('age', '($model->upcoming != date("Y-m-d")) ? $model->age+1 : $model->age'); $store = new \GO\Base\Data\DbStore('GO\\Addressbook\\Model\\Contact', $columnModel, $_POST, $findParams); return $store->getData(); }
protected function actionGroupsWithResources($params) { $stmt = \GO\Calendar\Model\Group::model()->find(\GO\Base\Db\FindParams::newInstance()->order('t.name')->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('id', 1, '>'))); $response['results'] = array(); $response['total'] = 0; while ($group = $stmt->fetch()) { $record = $group->getAttributes('formatted'); if (\GO::modules()->customfields) { $record['customfields'] = \GO\Customfields\Controller\CategoryController::getEnabledCategoryData("GO\\Calendar\\Model\\Event", $group->id); } else { $record['customfields'] = array(); } $record['resources'] = array(); $calStmt = \GO\Calendar\Model\Calendar::model()->find(\GO\Base\Db\FindParams::newInstance()->permissionLevel(\GO\Base\Model\Acl::READ_PERMISSION)->joinCustomFields()->order('t.name')->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('group_id', $group->id))); while ($resource = $calStmt->fetch()) { $resourceRecord = $resource->getAttributes('formatted'); $record['resources'][] = $resourceRecord; } $num_resources = count($record['resources']); if ($num_resources > 0) { $response['results'][] = $record; $response['total'] += $num_resources; } } return $response; }
/** * Loads a store of menu items that can be a parent of the given menu item. * * @param int $id * @param int $site_id */ public function actionParentStore($id = false, $menu_id) { $findCriteria = \GO\Base\Db\FindCriteria::newInstance()->addCondition('menu_id', $menu_id); $findCriteria->addCondition('id', $id, '<>'); $findParams = \GO\Base\Db\FindParams::newInstance()->criteria($findCriteria); $store = new \GO\Base\Data\DbStore('GO\\Site\\Model\\MenuItem', new \GO\Base\Data\ColumnModel('GO\\Site\\Model\\MenuItem'), $_REQUEST, $findParams); echo $this->renderStore($store); }
protected function actionStore($params) { $groupId = $params['group_id']; $columnModel = new \GO\Base\Data\ColumnModel(\GO\Ipwhitelist\Model\IpAddress::model()); $storeFindParams = \GO\Base\Db\FindParams::newInstance()->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('group_id', $groupId))->order('ip_address'); $store = new \GO\Base\Data\DbStore('GO\\Ipwhitelist\\Model\\IpAddress', $columnModel, $params, $storeFindParams); echo $this->renderStore($store); }
protected function actionGetUsage($params) { $domains = json_decode($params['domains']); $response['success'] = true; $record = \GO\Postfixadmin\Model\Mailbox::model()->find(\GO\Base\Db\FindParams::newInstance()->single()->select('SUM(`usage`) AS `usage`')->joinModel(array('model' => 'GO\\Postfixadmin\\Model\\Domain', 'localField' => 'domain_id', 'tableAlias' => 'd'))->criteria(\GO\Base\Db\FindCriteria::newInstance()->addInCondition('domain', $domains, 'd'))); $response['usage'] = $record->usage; return $response; }
protected function getStoreParams($params) { if (!empty($params['active'])) { return \GO\Base\Db\FindParams::newInstance()->select('t.*')->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('due_time', 0, '=', 't', false)->addCondition('due_time', mktime(0, 0, 0), '>=', 't', false))->order('id', 'DESC'); } else { return \GO\Base\Db\FindParams::newInstance()->select('t.*'); } }
protected function actionDisplay($params) { $findParams = \GO\Base\Db\FindParams::newInstance()->select('count(*) AS count')->join(\GO\Base\Model\ReminderUser::model()->tableName(), \GO\Base\Db\FindCriteria::newInstance()->addModel(\GO\Base\Model\Reminder::model())->addCondition('id', 'ru.reminder_id', '=', 't', true, true), 'ru')->criteria(\GO\Base\Db\FindCriteria::newInstance()->addModel(\GO\Base\Model\ReminderUser::model(), 'ru')->addCondition('user_id', \GO::user()->id, '=', 'ru')->addCondition('time', time(), '<', 'ru')); $model = \GO\Base\Model\Reminder::model()->findSingle($findParams); $html = ""; $this->fireEvent('reminderdisplay', array($this, &$html, $params)); $this->render("Reminder", array('count' => intval($model->count), 'html' => $html)); }
/** * Loads a store of content items of the current website * * @param int $id * @param int $site_id */ public function actionContentStore($menu_id) { $menu = \GO\Site\Model\Menu::model()->findByPk($menu_id); $findCriteria = \GO\Base\Db\FindCriteria::newInstance()->addCondition('site_id', $menu->site_id); $findParams = \GO\Base\Db\FindParams::newInstance()->criteria($findCriteria); $store = new \GO\Base\Data\DbStore('GO\\Site\\Model\\Content', new \GO\Base\Data\ColumnModel('GO\\Site\\Model\\Content'), $_REQUEST, $findParams); echo $this->renderStore($store); }
/** * Get enabled categories for a model. * * @param string $modelName The name of the model that controls the disabled categories. eg. \GO\Addressbook\Model\Addressbook controls them for \GO\Addressbook\Model\Contact * @param int $modelId * @return array */ public function getEnabledIds($modelName, $modelId) { $stmt = $this->find(\GO\Base\Db\FindParams::newInstance()->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('model_name', $modelName)->addCondition('model_id', $modelId))); $ids = array(); while ($enabled = $stmt->fetch()) { $ids[] = $enabled->category_id; } return $ids; }
protected function actionSelectStore($params) { $columnModel = new \GO\Base\Data\ColumnModel(\GO\Customfields\Model\Field::model()); $columnModel->formatColumn('extends_model', '$model->category->extends_model', array(), 'category_id'); $columnModel->formatColumn('full_info', '"[".\\GO::t($model->category->extends_model,"customfields")."] ".$model->category->name." : ".$model->name." (col_".$model->id.")"', array(), 'category_id'); $findParams = \GO\Base\Db\FindParams::newInstance()->joinModel(array('model' => 'GO\\Customfields\\Model\\Category', 'localTableAlias' => 't', 'localField' => 'category_id', 'foreignField' => 'id', 'tableAlias' => 'c'))->criteria(\GO\Base\Db\FindCriteria::newInstance()->addInCondition('extends_model', array('GO\\Addressbook\\Model\\Contact', 'GO\\Addressbook\\Model\\Company', 'GO\\Projects2\\Model\\Project', 'GO\\Base\\Model\\User'), 'c')->addInCondition('datatype', array('GO\\Addressbook\\Customfieldtype\\Contact', 'GO\\Addressbook\\Customfieldtype\\Company'), 't')); $store = new \GO\Base\Data\DbStore('GO\\Customfields\\Model\\Field', $columnModel, $params, $findParams); echo $this->renderStore($store); }
public function actionSavedExportsStore($className) { $columnModel = new ColumnModel(SavedExport::model()); // "t.name as text" needs to be added because this store is also used to create the menu. (And the menu expects the "text" property for it's label) $findParams = FindParams::newInstance()->select('t.*,t.name as text')->criteria(FindCriteria::newInstance()->addCondition('class_name', $className)); $store = new DbStore('GO\\Base\\Model\\SavedExport', $columnModel, GO::request()->post, $findParams); $store->defaultSort = 'id'; echo $this->render('store', array('store' => $store)); }
public function getGroupCalendars() { $findParams = \GO\Base\Db\FindParams::newInstance()->select('t.*')->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('view_id', $this->id, '=', 'vgr')); $findParams->joinModel(array('model' => 'GO\\Base\\Model\\User', 'localField' => 'user_id', 'tableAlias' => 'usr')); $findParams->joinModel(array('model' => 'GO\\Base\\Model\\UserGroup', 'localField' => 'user_id', 'foreignField' => 'user_id', 'tableAlias' => 'usg')); $findParams->joinModel(array('model' => 'GO\\Base\\Model\\Group', 'localField' => 'group_id', 'localTableAlias' => 'usg', 'tableAlias' => 'grp')); $findParams->joinModel(array('model' => 'GO\\Calendar\\Model\\ViewGroup', 'localField' => 'id', 'localTableAlias' => 'grp', 'foreignField' => 'group_id', 'tableAlias' => 'vgr', 'criteria' => \GO\Base\Db\FindCriteria::newInstance()->addCondition('view_id', $this->id, '=', 'vgr'))); return Calendar::model()->find($findParams); }
public function formatRawOutput($key, &$attributes, \GO\Customfields\Model\AbstractCustomFieldsRecord $model) { $column = $model->getColumn($key); if (!$column) { return null; } $fieldId = $column['customfield']->id; $findParams = \GO\Base\Db\FindParams::newInstance()->ignoreAcl()->order('mf.order')->joinModel(array('model' => 'GO\\Site\\Model\\MultifileFile', 'localTableAlias' => 't', 'localField' => 'id', 'foreignField' => 'file_id', 'tableAlias' => 'mf'))->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('model_id', $model->model_id, '=', 'mf')->addCondition('field_id', $fieldId, '=', 'mf')); return \GO\Files\Model\File::model()->find($findParams, 'false', true); }
public static function head() { echo '<style>'; $findParams = \GO\Base\Db\FindParams::newInstance()->joinRelation('category')->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('behave_as_module', 1)->addCondition('show_in_startmenu', 1, '=', 'category', false)); $stmt = Model\Bookmark::model()->find($findParams); while ($bookmark = $stmt->fetch()) { echo '.go-menu-icon-bookmarks-id-' . $bookmark->id . '{background-image:url(' . $bookmark->thumbUrl . ')}'; } echo '</style>'; }
protected function getStoreParams($params) { $sort = 'ctime'; $dir = 'DESC'; if (!empty($params['sort'])) { $sort = $params['sort']; $dir = $params['dir']; } return \GO\Base\Db\FindParams::newInstance()->ignoreAcl()->select('t.*, category.name as category_name')->order($sort, $dir)->joinRelation('category', 'LEFT')->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('model_id', $params['model_id'])->addCondition('model_type_id', \GO\Base\Model\ModelType::model()->findByModelName($params['model_name']))); }
protected function getStoreParams($params) { if (empty($params['account_id'])) { $findParams = \GO\Base\Db\FindParams::newInstance()->select('t.*')->joinModel(array('model' => 'GO\\Email\\Model\\AccountSort', 'foreignField' => 'account_id', 'localField' => 'account_id', 'type' => 'LEFT', 'tableAlias' => 'sor', "criteria" => \GO\Base\Db\FindCriteria::newInstance()->addCondition('user_id', \GO::user()->id, "=", 'sor')))->ignoreAdminGroup()->permissionLevel(\GO\Base\Model\Acl::CREATE_PERMISSION)->order(array('order', 'default'), array('DESC', 'DESC')); } else { $findParams = \GO\Base\Db\FindParams::newInstance(); $findParams->getCriteria()->addCondition("account_id", $params['account_id'])->addCondition("default", 1, '!='); } return $findParams; }
/** * Search through the site content * * @param array $params * @throws Exception */ protected function actionSearch($params) { if (!isset($params['searchString'])) { throw new \Exception('No searchstring provided'); } $searchString = $params['searchString']; $searchParams = \GO\Base\Db\FindParams::newInstance()->select('*')->criteria(\GO\Base\Db\FindCriteria::newInstance()->addSearchCondition('title', $searchString, false)->addSearchCondition('meta_title', $searchString, false)->addSearchCondition('meta_description', $searchString, false)->addSearchCondition('meta_keywords', $searchString, false)->addSearchCondition('content', $searchString, false)); $columnModel = new \GO\Base\Data\ColumnModel(); $store = new \GO\Base\Data\DbStore('GO\\Site\\Model\\Content', $columnModel, $params, $searchParams); echo $this->render('search', array('searchResults' => $store)); }
protected function actionEnableStore($params) { $columnModel = new \GO\Base\Data\ColumnModel(\GO\Customfields\Model\Block::model()); $columnModel->formatColumn('col_id', '"col_".$model->customField->id', array(), 'field_id'); $columnModel->formatColumn('customfield_name', '$model->customField->name', array(), 'field_id'); $columnModel->formatColumn('customfield_datatype', '$model->customField->datatype', array(), 'field_id'); $columnModel->formatColumn('extends_model', '$model->customField->category->extends_model', array(), 'field_id'); $columnModel->formatColumn('enabled', '!empty($model->enabled_block_id)', array(), 'enabled_block_id'); $findParams = \GO\Base\Db\FindParams::newInstance()->select('t.*,eb.block_id AS enabled_block_id')->joinModel(array('model' => 'GO\\Customfields\\Model\\EnabledBlock', 'localTableAlias' => 't', 'localField' => 'id', 'foreignField' => 'block_id', 'tableAlias' => 'eb', 'type' => 'LEFT', 'criteria' => \GO\Base\Db\FindCriteria::newInstance()->addCondition('model_type_name', $params['model_name'], '=', 'eb')->addCondition('model_id', $params['model_id'], '=', 'eb')))->joinModel(array('model' => 'GO\\Customfields\\Model\\Field', 'localTableAlias' => 't', 'localField' => 'field_id', 'foreignField' => 'id', 'tableAlias' => 'cf', 'type' => 'INNER'))->joinModel(array('model' => 'GO\\Customfields\\Model\\Category', 'localTableAlias' => 'cf', 'localField' => 'category_id', 'foreignField' => 'id', 'tableAlias' => 'cfcat', 'type' => 'INNER'))->join('go_acl', \GO\Base\Db\FindCriteria::newInstance()->addRawCondition('a.acl_id', 'cfcat.acl_id'), 'a')->join('go_users_groups', \GO\Base\Db\FindCriteria::newInstance()->addRawCondition('a.group_id', 'ug.group_id'), 'ug', 'LEFT')->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('user_id', \GO::user()->id, '=', 'a', false)->addCondition('user_id', \GO::user()->id, '=', 'ug', false)); $store = new \GO\Base\Data\DbStore('GO\\Customfields\\Model\\Block', $columnModel, $params, $findParams); echo $this->renderStore($store); }
public static function getEnabledBlocks($modelId, $listedModelTypeName, $listingModelName) { if ($listingModelName == 'GO\\Addressbook\\Model\\Contact') { $dataType = 'GO\\Addressbook\\Customfieldtype\\Contact'; } else { $dataType = 'GO\\Addressbook\\Customfieldtype\\Company'; } return self::model()->find(\GO\Base\Db\FindParams::newInstance()->joinModel(array('model' => 'GO\\Customfields\\Model\\Block', 'localTableAlias' => 't', 'localField' => 'block_id', 'foreignField' => 'id', 'tableAlias' => 'b', 'type' => 'INNER'))->joinModel(array('model' => 'GO\\Customfields\\Model\\Field', 'localTableAlias' => 'b', 'localField' => 'field_id', 'foreignField' => 'id', 'tableAlias' => 'cf', 'type' => 'INNER'))->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('model_id', $modelId, '=', 't')->addCondition('model_type_name', $listedModelTypeName, '=', 't')->addCondition('datatype', $dataType, '=', 'cf'))->debugSql()); // ->findByAttributes(array( // 'model_id' => $modelId, // 'model_type_name' => $listedModelTypeName // )); }
public function getItemNames($forModelId, $forModelName) { $modelUnderBlock = \GO::getModel($this->customField->category->extends_model); $cfTableName = 'cf_' . $modelUnderBlock->tableName(); $stmt = $modelUnderBlock->find(\GO\Base\Db\FindParams::newInstance()->ignoreAcl()->join($cfTableName, \GO\Base\Db\FindCriteria::newInstance()->addRawCondition('cf.model_id', 't.id'), 'cf', 'INNER')->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('col_' . $this->field_id, $forModelId . ':%', 'LIKE', 'cf'))); $itemNamesArr = array(); foreach ($stmt as $item) { $name = $item->className() == 'GO\\Addressbook\\Model\\Company' || $item->className() == 'GO\\Addressbook\\Model\\Contact' ? $item->name . ' (' . $item->addressbook->name . ')' : $item->name; $itemNamesArr[] = array('model_id' => $item->id, 'model_name' => $item->className(), 'item_name' => $name); } usort($itemNamesArr, function ($a, $b) { return $a['item_name'] >= $b['item_name'] ? 1 : -1; }); return $itemNamesArr; }
/** * Return all new items for a grid. * So this are the items that are not already selected. * * Parameters: * model_id = The value of one of the keys from the combined primary key of the linkModel that is not given in the linkModelField; * Example: The combined key of the linkModel is: [user_id,tasklist_id]. * The given linkModelField is: [tasklist_id]. * Then the model_id needs to be the other value of the combined key so in this example: The value for [user_id] * * * @param Array $params * @return type */ protected function actionSelectNewStore($params) { $model = \GO::getModel($this->modelName()); $linkModel = \GO::getModel($this->linkModelName()); $store = \GO\Base\Data\Store::newInstance($model); $joinCriteria = \GO\Base\Db\FindCriteria::newInstance()->addCondition($this->getRemoteKey(), $params['model_id'], '=', 'lt')->addCondition($model->primaryKey(), 'lt.' . $this->linkModelField(), '=', 't', true, true); $this->formatColumns($store->getColumnModel()); $findParams = $store->getDefaultParams($params); if ($this->uniqueSelection) { $findParams->join($linkModel->tableName(), $joinCriteria, 'lt', 'LEFT'); $findCriteria = \GO\Base\Db\FindCriteria::newInstance()->addCondition($this->linkModelField(), null, 'IS', 'lt'); $findParams->criteria($findCriteria); } $availableModels = $model->find($findParams); $store->setStatement($availableModels); return $store->getData(); }
protected function actionGetRecipientsAsString($params) { if (empty($params['groups'])) { throw new \Exception(); } $recipients = new \GO\Base\Mail\EmailRecipients(); $groupIds = json_decode($params['groups']); foreach ($groupIds as $groupId) { //ignore acl because members may use groups even without permissions $group = \GO\Base\Model\Group::model()->findByPk($groupId, false, true); if ($group) { $users = $group->users(\GO\Base\Db\FindParams::newInstance()->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('email', '', '!='))); while ($user = $users->fetch()) { $recipients->addRecipient($user->email, $user->name); } } } return array('success' => true, 'recipients' => (string) $recipients); }
protected function getStoreParams($params) { if (isset($params['node'])) { $parent_id = $params['node']; } else { $parent_id = $params['parent_id']; } $field_id = str_replace('col_', '', $params['field_id']); $fieldModel = \GO\Customfields\Model\Field::model()->findByPk($field_id, false, true); if ($params['parent_id'] == 0 && $fieldModel->datatype == 'GO\\Customfields\\Customfieldtype\\TreeselectSlave') { return \GO\Base\Db\FindParams::newInstance()->order(array("parent_id", "sort"))->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('field_id', $fieldModel->treemaster_field_id)); } else { return \GO\Base\Db\FindParams::newInstance()->order("sort")->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('field_id', $field_id)->addCondition('parent_id', $parent_id)); } // return array( // 'where'=>'field_id=:field_id AND parent_id=:parent_id', // 'bindParams'=>array(':field_id'=>$params['field_id'], ':parent_id'=>$parent_id), // 'order'=>'sort' // ); }
/** * Get the data for the grid that shows all the tasks from the selected calendars. * * @param Array $params * @return Array The array with the data for the grid. */ protected function actionPortletGrid($params) { $local_time = time(); $year = date("Y", $local_time); $month = date("m", $local_time); $day = date("j", $local_time); $periodStartTime = mktime(0, 0, 0, $month, $day, $year); $periodEndTime = mktime(0, 0, 0, $month, $day + 2, $year); $today_end = mktime(0, 0, 0, $month, $day + 1, $year); $joinCriteria = \GO\Base\Db\FindCriteria::newInstance()->addCondition('user_id', \GO::user()->id, '=', 'pt')->addCondition('calendar_id', 'pt.calendar_id', '=', 't', true, true); $calendarJoinCriteria = \GO\Base\Db\FindCriteria::newInstance()->addCondition('calendar_id', 'tl.id', '=', 't', true, true); $findParams = \GO\Base\Db\FindParams::newInstance()->select('t.*, tl.name AS calendar_name')->join(\GO\Calendar\Model\PortletCalendar::model()->tableName(), $joinCriteria, 'pt')->join(\GO\Calendar\Model\Calendar::model()->tableName(), $calendarJoinCriteria, 'tl'); $events = \GO\Calendar\Model\Event::model()->findCalculatedForPeriod($findParams, $periodStartTime, $periodEndTime); $store = new \GO\Base\Data\ArrayStore(); foreach ($events as $event) { $record = $event->getResponseData(); $record['day'] = $event->getAlternateStartTime() < $today_end ? \GO::t('today') : \GO::t('tomorrow'); $record['time'] = $event->getEvent()->all_day_event == 1 ? '-' : $record['time']; $store->addRecord($record); } return $store->getData(); }
protected function beforeStoreStatement(array &$response, array &$params, \GO\Base\Data\AbstractStore &$store, \GO\Base\Db\FindParams $storeParams) { //SELECT * FROM cal_categories t //LEFT JOIN go_acl ON (`t`.`acl_id` = go_acl.acl_id AND (go_acl.user_id=57 OR go_acl.group_id IN (2))) //WHERE t.calendar_id = 0 AND go_acl.acl_id IS NOT NULL OR t.calendar_id=56 $groupIds = \GO\Base\Model\User::getGroupIds(\GO::user()->id); $storeCriteria = $storeParams->getCriteria(); $joinUserGroupCriteria = \GO\Base\Db\FindCriteria::newInstance()->addCondition('user_id', \GO::user()->id, '=', 'go_acl', false)->addInCondition('group_id', $groupIds, 'go_acl', false); $joinCriteria = \GO\Base\Db\FindCriteria::newInstance()->addCondition('acl_id', 'go_acl.acl_id', '=', 't', true, true)->mergeWith($joinUserGroupCriteria); $storeParams->join('go_acl', $joinCriteria, 'go_acl', 'LEFT'); if (!empty($params['global_categories']) && !empty($params['calendar_id'])) { $storeCriteria->addCondition('calendar_id', 0, '=', 't', false); $storeCriteria->addCondition('acl_id', NULL, 'IS NOT', 'go_acl'); $storeCriteria->addCondition('calendar_id', $params['calendar_id'], '=', 't', false); } elseif (!empty($params['calendar_id'])) { $storeCriteria->addCondition('calendar_id', $params['calendar_id']); } else { $storeCriteria->addCondition('calendar_id', 0); } $storeParams->ignoreAcl(); return parent::beforeStoreStatement($response, $params, $store, $storeParams); }