/** * Test adding and getting back class * * @return void * @author Dan Cox */ public function test_addGet() { $arr = array('task' => array('name' => 'Command', 'description' => '', 'actions' => ['main', 'run']), 'class' => 'TEST'); $this->library->add($arr); // Now find this by its command name $val = $this->library->find('Command:run'); $this->assertEquals('TEST', $val); }
/** * Deactivate a module * * @return void * @author Dan Cox */ public function deactivate($name) { $module = $this->library->find($name); if (!is_null($module)) { $probe = $this->get('moduleprobe'); $probe->load($module); $probe->deactivateModule(); return true; } throw new \Exception("Unable to find this module in the library"); }
/** * Finds the first entity by the given parameters * * @param integer|array|string $param * @return Object $entity */ public function first($params, $value = null) { if (is_numeric($params)) { $entity = $this->entity->find($id); } if (is_array($params)) { $entity = $this->entity->where($params)->first(); } if (is_string($params)) { $entity = $this->entity->where($params, $value)->first(); } return $entity; }
/** * Before save * * @param ObjectModel $model * @return boolean true */ public function beforeSave(&$model) { if (is_numeric($this->Model->id)) { $this->_action = 'edit'; $newData = $this->Model->find('first', array('conditions' => array("{$this->Model->name}.id" => $this->Model->data[$this->Model->name]['id']))); foreach ($newData[$this->Model->name] as $input => $value) { $this->_oldData .= "{$input} :: {$value}"; } } else { $this->_action = 'add'; } return true; }
/** * blogBlogPostBeforeRender * * @param CakeEvent $event */ public function blogBlogPostsBeforeRender(CakeEvent $event) { if (!BcUtil::isAdminSystem()) { return; } $View = $event->subject(); if (in_array($View->request->params['action'], $this->targetAction)) { $this->setUpModel(); $data = $this->KeywordConfigModel->find('first', array('conditions' => array('KeywordConfig.model' => 'BlogContent', 'KeywordConfig.content_id' => $View->viewVars['blogContent']['BlogContent']['id']))); if ($data) { $View->request->data['KeywordConfig'] = $data['KeywordConfig']; } } }
/** * Given the list of params in the params array, fetch the object * and store the values in the values array * * @param Object $block typically a Phone|Email|IM object * @param string $blockName name of the above object * @param array $params input parameters to find object * @param array $values output values of the object * @param array $ids the array that holds all the db ids * @param int $blockCount number of blocks to fetch * * @return array of $block objects. * @access public * @static */ function &getValues(&$block, $blockName, &$params, &$values, &$ids, $blockCount = 0) { $block->copyValues($params); $flatten = false; if (empty($blockCount)) { $blockCount = 1; $flatten = true; } else { $values[$blockName] = array(); $ids[$blockName] = array(); } $blocks = array(); // we first get the primary location due to the order by clause $block->orderBy('is_primary desc'); $block->find(); for ($i = 0; $i < $blockCount; $i++) { if ($block->fetch()) { if ($flatten) { CRM_Core_DAO::storeValues($block, $values); $ids[$blockName] = $block->id; } else { $values[$blockName][$i + 1] = array(); CRM_Core_DAO::storeValues($block, $values[$blockName][$i + 1]); $ids[$blockName][$i + 1] = $block->id; } $blocks[$i + 1] = clone $block; } } return $blocks; }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { $Object = Object::find($id); $Object->name = Input::get('name'); $Object->save(); //return Redirect::route('index'); return Response::json($Object); }
/** * update. * * @param Int $accountId Account ID * @param Int $addId 加粉丝的组自增ID * @param array $groupIds 粉丝组group_id * @param array $count 数量 */ public function cutFanCount($accountId, $addId, $groupIds, $count) { /* * 增加 */ $addFanGroup = $this->model->find($addId); $_saveAddInfo['fan_count'] = $addFanGroup->fan_count + $count; $this->_savePost($addFanGroup, $_saveAddInfo); /* * 减掉 */ foreach ($groupIds as $groupId => $groupCount) { $cutFanGroup = $this->getGroupByGroupid($accountId, $groupId); $_saveCutInfo['fan_count'] = $cutFanGroup->fan_count - $groupCount; $this->_savePost($cutFanGroup, $_saveCutInfo); } }
public function run() { /*{{{*/ if (class_exists($this->controller)) { $instance = Object::find($this->controller); } else { throw new QException(100); } if (method_exists($instance, $this->action)) { $action = $this->action; } else { throw new QException(101); } if (method_exists($instance, $this->_prefix_method)) { $instance->dispatch($this->_prefix_method); } $instance->dispatch($action); if (method_exists($instance, $this->_suffix_method)) { $instance->dispatch($this->_suffix_method); } }
/** * Format the arguments into a useable state * * @return Array */ public function formatArgs($args) { // The first argument is always the file unset($args[0]); if (isset($args[1])) { $command = explode(':', $args[1]); unset($args[1]); } else { // No Command Specified. return array(); } try { $action = isset($command[1]) ? $command[1] : 'main'; $cmd = $this->library->find($command[0] . ':' . $action); $task = get_class($cmd); return array('task' => $task, 'action' => $action, 'params' => $args); } catch (\Exception $e) { // No Command FOUND return array(); } }
/** * 保存するデータの生成 * * @param Object $Model * @param int $contentId * @return array */ private function _generateContentSaveData($Model, $contentId) { $params = Router::getParams(); $this->PetitBlogCustomFieldConfigModel = ClassRegistry::init('PetitBlogCustomField.PetitBlogCustomFieldConfig'); $data = array(); if ($Model->alias == 'BlogContent') { $modelId = $contentId; $oldModelId = $params['pass'][0]; } if ($contentId) { $data = $this->PetitBlogCustomFieldConfigModel->find('first', array('conditions' => array('PetitBlogCustomFieldConfig.blog_content_id' => $contentId))); } if ($params['action'] != 'admin_ajax_copy') { if ($data) { // 編集時 $data['PetitBlogCustomFieldConfig'] = array_merge($data['PetitBlogCustomFieldConfig'], $Model->data['PetitBlogCustomFieldConfig']); } else { // 追加時 $data['PetitBlogCustomFieldConfig']['blog_content_id'] = $contentId; } } else { // Ajaxコピー処理時に実行 // ブログコピー保存時にエラーがなければ保存処理を実行 if (empty($Model->validationErrors)) { $_data = $this->PetitBlogCustomFieldConfigModel->find('first', array('conditions' => array('PetitBlogCustomFieldConfig.blog_content_id' => $oldModelId), 'recursive' => -1)); // XXX もしキーワード設定の初期データ作成を行ってない事を考慮して判定している if ($_data) { // コピー元データがある時 $data['PetitBlogCustomFieldConfig']['blog_content_id'] = $contentId; unset($data['PetitBlogCustomFieldConfig']['id']); } else { // コピー元データがない時 $data['PetitBlogCustomFieldConfig']['blog_content_id'] = $modelId; } } } return $data; }
public static function prepareActivityLog($shareData) { $aApp = array(App::SHARECALENDAR => 'calendar', App::SHAREEVENT => 'calendar', App::SHARETODO => App::SHARECALENDAR); //shared_with_by, shared_user_self,shared_group_self,shared_link_self if (array_key_exists($shareData['itemType'], $aApp)) { $sType = ''; $sL10nDescr = ''; if ($shareData['itemType'] === App::SHARECALENDAR) { $sType = App::SHARECALENDARPREFIX; $sL10nDescr = 'calendar'; } if ($shareData['itemType'] === App::SHAREEVENT) { $sType = App::SHAREEVENTPREFIX; $sL10nDescr = 'event'; } if ($shareData['itemType'] === App::SHARETODO) { $sType = App::SHARETODOPREFIX; $sL10nDescr = 'todo'; } $sApp = $aApp[$shareData['itemType']]; $l = \OC::$server->getL10N(App::$appname); $type = 'shared_' . $sApp; if ($shareData['token'] !== '' && $shareData['shareType'] === \OCP\Share::SHARE_TYPE_LINK) { $shareData['itemSource'] = App::validateItemSource($shareData['itemSource'], $sType); if ($shareData['itemType'] === App::SHAREEVENT || $shareData['itemType'] === App::SHARECALENDAR) { $link = \OC::$server->getURLGenerator()->linkToRoute(App::$appname . '.public.index', ['token' => $shareData['token']]); } if ($shareData['itemType'] === App::SHARETODO) { $link = \OC::$server->getURLGenerator()->linkToRoute('tasksplus.public.index', ['token' => $shareData['token']]); } if ($shareData['itemType'] === App::SHAREEVENT || $shareData['itemType'] === App::SHARETODO) { $aObject = Object::find($shareData['itemSource']); $aCalendar = Calendar::find($aObject['calendarid']); $description = $l->t($sL10nDescr) . ' ' . $aObject['summary'] . ' (' . $l->t('calendar') . ' ' . $aCalendar['displayname'] . ')'; } else { $description = $l->t($sL10nDescr) . ' ' . $shareData['itemTarget']; } \OC::$server->getActivityManager()->publishActivity(App::$appname, 'shared_link_self_' . $sApp, array($description), '', '', '', $link, \OCP\User::getUser(), $type, ''); } if ($shareData['shareType'] === \OCP\Share::SHARE_TYPE_USER) { $link = ''; $shareData['itemSource'] = App::validateItemSource($shareData['itemSource'], $sType); if ($shareData['itemType'] === App::SHARETODO) { $link = \OC::$server->getURLGenerator()->linkToRoute('tasksplus.page.index') . '#' . urlencode($shareData['itemSource']); } if ($shareData['itemType'] === App::SHAREEVENT) { $link = \OC::$server->getURLGenerator()->linkToRoute(App::$appname . '.page.index') . '#' . urlencode($shareData['itemSource']); } $description = $shareData['itemTarget']; if ($shareData['itemType'] === App::SHARETODO || $shareData['itemType'] === App::SHAREEVENT) { $aObject = Object::find($shareData['itemSource']); $aCalendar = Calendar::find($aObject['calendarid']); $description = $aObject['summary'] . ' (' . $l->t('calendar') . ' ' . $aCalendar['displayname'] . ')'; } \OC::$server->getActivityManager()->publishActivity(App::$appname, 'shared_user_self_' . $sApp, array($l->t($sL10nDescr) . ' ' . $description, $shareData['shareWith']), '', '', '', $link, \OCP\User::getUser(), $type, ''); \OC::$server->getActivityManager()->publishActivity(App::$appname, 'shared_with_by_' . $sApp, array($l->t($sL10nDescr) . ' ' . $description, \OCP\User::getUser()), '', '', '', $link, $shareData['shareWith'], $type, ''); } if ($shareData['shareType'] === \OCP\Share::SHARE_TYPE_GROUP) { $link = ''; $shareData['itemSource'] = App::validateItemSource($shareData['itemSource'], $sType); if ($shareData['itemType'] === App::SHARETODO) { $link = \OC::$server->getURLGenerator()->linkToRoute('tasksplus.page.index') . '#' . urlencode($shareData['itemSource']); } if ($shareData['itemType'] === App::SHAREEVENT) { $link = \OC::$server->getURLGenerator()->linkToRoute('calendar.page.index') . '#' . urlencode($shareData['itemSource']); } $description = $shareData['itemTarget']; if ($shareData['itemType'] === App::SHARETODO || $shareData['itemType'] === App::SHAREEVENT) { $aObject = Object::find($shareData['itemSource']); $aCalendar = Calendar::find($aObject['calendarid']); $description = $aObject['summary'] . ' (' . $l->t('calendar') . ' ' . $aCalendar['displayname'] . ')'; } \OC::$server->getActivityManager()->publishActivity(App::$appname, 'shared_group_self_' . $sApp, array($l->t($sL10nDescr) . ' ' . $description, $shareData['shareWith']), '', '', '', $link, \OCP\User::getUser(), $type, ''); $usersInGroup = \OC_Group::usersInGroup($shareData['shareWith']); foreach ($usersInGroup as $user) { \OC::$server->getActivityManager()->publishActivity(App::$appname, 'shared_with_by_' . $sApp, array($l->t($sL10nDescr) . ' ' . $description, \OCP\User::getUser()), '', '', '', $link, $user, 'shared_' . $sApp, ''); } } } }
public function getAction() { /*{{{*/ $web = Object::find("Web"); return $web->action; }
private function isDuplicate($insertid) { $newobject = Object::find($insertid); $endDate = $newobject['enddate']; if (!$newobject['enddate']) { $endDate = null; } $stmt = \OCP\DB::prepare('SELECT COUNT(*) AS `COUNTING` FROM `' . App::CldObjectTable . '` `CO` INNER JOIN `' . App::CldCalendarTable . '` ON `CO`.`calendarid`=`' . App::CldCalendarTable . '`.`id` WHERE `CO`.`objecttype`=? AND `CO`.`startdate`=? AND `CO`.`enddate`=? AND `CO`.`repeating`=? AND `CO`.`summary`=? AND `CO`.`calendardata`=? AND `' . App::CldCalendarTable . '`.`userid` = ? AND `CO`.`calendarid`=?'); $result = $stmt->execute(array($newobject['objecttype'], $newobject['startdate'], $endDate, $newobject['repeating'], $newobject['summary'], $newobject['calendardata'], $this->userid, $newobject['calendarid'])); $result = $result->fetchRow(); if ($result['COUNTING'] >= 2) { return true; } return false; }
/** * Take in an order array and sorts the list based on that order specification * and creates new weights for it. If no foreign key is supplied, all lists * will be sorted. * * @todo foreign key independent * @param Object $Model * @param array $order * @param mixed $foreign_key * $returns boolean true if successfull */ public function sortby(&$Model, $order, $foreign_key = null) { $fields = array($Model->primaryKey, $this->settings[$Model->alias]['field']); $conditions = array(1 => 1); if ($this->settings[$Model->alias]['foreign_key']) { if (!$foreign_key) { return false; } $fields[] = $this->settings[$Model->alias]['foreign_key']; $conditions = array($Model->alias . '.' . $this->settings[$Model->alias]['foreign_key'] => $foreign_key); } $all = $Model->find('all', array('fields' => $fields, 'conditions' => $conditions, 'recursive' => -1, 'order' => $order)); $i = 1; foreach ($all as $key => $one) { $all[$key][$Model->alias][$this->settings[$Model->alias]['field']] = $i++; } return $Model->saveAll($all); }
/** * @brief exports an event and convert all times to UTC * @param integer $id id of the event * @return string */ private static function event($id) { $event = Object::find($id); $return = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:ownCloud Calendar " . \OCP\App::getAppVersion(App::$appname) . "\nX-WR-CALNAME:" . $event['summary'] . "\n"; $object = VObject::parse($event['calendardata']); if ($object->VTIMEZONE) { $return .= self::addVtimezone(); } $return .= self::generateEvent($event); $return .= "END:VCALENDAR"; return $return; }
<?php defined('APP_PATH') or exit("项目目录未定义,请在入口文件定义mvc所在目录"); defined('LIB_VERION') or define('LIB_VERION', '2.0'); include LIB_PATH . '/Public/common.class.php'; include LIB_PATH . '/SamLoader.php'; if (isset($argv) && !empty($argv)) { define('RUN_MODE', 'cli'); $options = getopt("m:"); if (!empty($options['m'])) { $_GET['method'] = $options['m']; } else { $_GET['method'] = 'index.index'; } } else { define('RUN_MODE', 'http'); } if (!isset($_GET['method'])) { $_GET['method'] = 'index.index'; } $webapp = Object::find("Web"); try { $webapp->parseRoute(); $webapp->run(); } catch (QException $e) { echo $e->getError(); }
/** * pagesBeforeRender * * @param CakeEvent $event */ public function pagesBeforeRender(CakeEvent $event) { if (BcUtil::isAdminSystem()) { return; } $Controller = $event->subject(); if (!empty($Controller->request->url)) { $this->KeywordModel = ClassRegistry::init($this->plugin . '.Keyword'); // XXX 参考:/baser/views/helpers/bc_page.php:beforeRender() $param = Configure::read('BcRequest.pureUrl'); if ($param && preg_match('/\\/$/is', $param)) { $param .= 'index'; } // PC版固定ページのデータを取得する $pageDataPc = $Controller->Page->findByUrl('/' . $param, array('fields' => 'id')); // PC版固定ページのデータを元に、キーワードデータを取得する $judgeSmartPhoneUseKeywordPc = false; $judgeMobileUseKeywordPc = false; if ($pageDataPc) { $keywordPc = $this->KeywordModel->find('first', array('conditions' => array('Keyword.model' => 'Page', 'Keyword.model_id' => $pageDataPc['Page']['id']))); if ($keywordPc) { // キーワード・データに「スマホ共通利用」指定があれば、そのデータを利用する if ($keywordPc['Keyword']['linked_smartphone']) { $judgeSmartPhoneUseKeywordPc = true; } // キーワード・データに「モバイル共通利用」指定があれば、そのデータを利用する if ($keywordPc['Keyword']['linked_mobile']) { $judgeMobileUseKeywordPc = true; } } } // プレフィックスが付いた場合 if (Configure::read('BcRequest.agent')) { $param = Configure::read('BcRequest.agentPrefix') . '/' . $param; } if (!$param || $param == 'smartphone/' || $param == 'mobile/') { $param = $param . 'index'; } $patternMobile = '/^' . Configure::read('BcAgent.mobile.prefix') . '\\//'; $patternSmartphone = '/^' . Configure::read('BcAgent.smartphone.prefix') . '\\//'; if (preg_match($patternMobile, $param)) { if ($judgeMobileUseKeywordPc) { $Controller->viewVars['keywords'] = $keywordPc['Keyword']['keywords']; $Controller->viewVars['Keyword'] = $keywordPc['Keyword']; return; } } elseif (preg_match($patternSmartphone, $param)) { if ($judgeSmartPhoneUseKeywordPc) { $Controller->viewVars['keywords'] = $keywordPc['Keyword']['keywords']; $Controller->viewVars['Keyword'] = $keywordPc['Keyword']; return; } } $pageData = $Controller->Page->findByUrl('/' . $param, array('fields' => 'id')); if ($pageData) { $keyword = $this->KeywordModel->find('first', array('conditions' => array('Keyword.model' => 'Page', 'Keyword.model_id' => $pageData['Page']['id']))); if ($keyword) { $Controller->viewVars['keywords'] = $keyword['Keyword']['keywords']; $Controller->viewVars['Keyword'] = $keyword['Keyword']; } } } }
/** * Find an element by Identifier * * @return Mixed * @author Dan Cox */ public function find($id) { return $this->entity->find($this->model, $id); }
/** * Given the list of params in the params array, fetch the object * and store the values in the values array * * @param Object $block typically a Phone|Email|IM|OpenID object * @param string $blockName name of the above object * @param array $values output values of the object * * @return array of $block objects. * @access public * @static */ static function retrieveBlock(&$block, $blockName) { // we first get the primary location due to the order by clause $block->orderBy('is_primary desc, id'); $block->find(); $count = 1; $blocks = array(); while ($block->fetch()) { CRM_Core_DAO::storeValues($block, $blocks[$count]); //unset is_primary after first block. Due to some bug in earlier version //there might be more than one primary blocks, hence unset is_primary other than first if ($count > 1) { unset($blocks[$count]['is_primary']); } $count++; } return $blocks; }
public function changeAvailabilityObjectState($id) { $input = Input::all(); $object = Object::find($id); $object->update(array('shown' => $input['shown'] == 'true' ? 1 : 0)); return Response::json(array('success' => true, 'object' => $object), 200); }
/** * Attempts to connect to a database through a named connection * * @author Dan Cox */ public function connect($name, $type = 'Annotation') { $this->connection = $this->collection->find($name); $this->map($type, 'Wasp\\Exceptions\\Database\\InvalidMetaDataType'); $this->createEntityManager(); }
private function getDefaultTpl($tpl_path = '') { /*{{{*/ if ($tpl_path == '') { $web = Object::find("Web"); $view_path = $web->view_path; $view_name = $web->view_name; $this->tpl_dir = $view_path; $tpl_path = $view_path . '/' . $view_name . '.' . $this->tpl_suffix; } else { $path = explode('/', $tpl_path); $this->tpl_dir = $path[0]; } return str_replace("\\", "/", $this->tpl_root . $tpl_path); }
/** * This will create weights based on display field. The purpose of the method is to create * weights for tables that existed before this behavior was added. * * @param Object $Model * @return boolean success */ public function resetweights(&$Model) { if ($this->settings[$Model->alias]['foreign_key']) { $temp = $Model->find('all', array('fields' => $this->settings[$Model->alias]['foreign_key'], 'group' => $this->settings[$Model->alias]['foreign_key'], 'recursive' => -1)); $foreign_keys = Set::extract($temp, '{n}.' . $Model->alias . '.' . $this->settings[$Model->alias]['foreign_key']); foreach ($foreign_keys as $fk) { $all = $Model->find('all', array('conditions' => array($this->settings[$Model->alias]['foreign_key'] => $fk), 'fields' => array($Model->displayField, $Model->primaryKey, $this->settings[$Model->alias]['field'], $this->settings[$Model->alias]['foreign_key']), 'order' => $Model->displayField)); $i = 1; foreach ($all as $key => $one) { $all[$key][$Model->alias][$this->settings[$Model->alias]['field']] = $i++; } if (!$Model->saveAll($all)) { return false; } } } else { $all = $Model->find('all', array('fields' => array($Model->displayField, $Model->primaryKey, $this->settings[$Model->alias]['field']), 'order' => $Model->displayField)); $i = 1; foreach ($all as $key => $one) { $all[$key][$Model->alias][$this->settings[$Model->alias]['field']] = $i++; } if (!$Model->saveAll($all)) { return false; } } return true; }
/** * Merge two models into one, by effectivly joining them. By default target fields and associations will be used, * but sources will be used where there the target isnt available or both where that is possible. You can override * this on a field and association(alias) basis should you need to. * * NB when merging with associations that are binded realtime, reset (2nd parameter of Model::bindModel) needs to be false * * @example $this->Post->merge(1,2,array('title'=>'source','author_id'=>'input'),array('Comment'=>'source'),$data); * @param Object $Model * @param int $target_id * @param int $source_id * @param array $field_options * @param array $data * @return boolean success */ function merge(&$Model, $target_id, $source_id, $field_options = array(), $assoc_options = array(), $data = array()) { $fields = am($this->settings[$Model->alias], $field_options); $target = $Model->find('first', array('conditions' => array($Model->primaryKey => $target_id), 'recursive' => -1)); $source = $Model->find('first', array('conditions' => array($Model->primaryKey => $source_id), 'recursive' => -1)); $new_values = array(); foreach ($fields as $key => $value) { switch ($value) { case 'source': $new_values[$key] = $source[$Model->alias][$key]; break; case 'target_source': $new_values[$key] = $target[$Model->alias][$key] . "\n " . $source[$Model->alias][$key]; break; case 'source_target': $new_values[$key] = $source[$Model->alias][$key] . "\n " . $target[$Model->alias][$key]; break; case 'input': $new_values[$key] = $data[$Model->alias][$key]; break; case 'target': case FALSE: default: break; } } // belongsTo is taken care of above with fields // hasOne - default is target, options are target, source, neither foreach ($Model->hasOne as $assoc_model => $assoc_setup) { $className = $assoc_setup['className']; $foreignKey = $assoc_setup['foreignKey']; $dependent = $assoc_setup['dependent']; if (!isset($assoc_options[$assoc_model]) && !isset($assoc_options['hasOne'][$assoc_model])) { $use = 'target'; // default behaviour } else { if (isset($assoc_options['hasOne']) && isset($assoc_options['hasOne'][$assoc_model])) { $use = $assoc_options['hasOne'][$assoc_model]; } else { $use = $assoc_options[$assoc_model]; } } switch ($use) { case 'neither': // delete or reset both if ($dependent) { $Model->{$assoc_model}->deleteAll(array($foreignKey => array($source_id, $target_id))); } else { $Model->{$assoc_model}->updateAll(array($foreignKey => NULL), array($foreignKey => array($source_id, $target_id))); } break; case 'target': // keep old target, delete or reset assoc for source if ($dependent) { $Model->{$assoc_model}->deleteAll(array($foreignKey => array($source_id))); } else { $Model->{$assoc_model}->updateAll(array($foreignKey => NULL), array($foreignKey => $source_id)); } break; case 'source': // delete or reset target, use source if ($dependent) { $Model->{$assoc_model}->deleteAll(array($foreignKey => array($target_id))); } else { $Model->{$assoc_model}->updateAll(array($foreignKey => NULL), array($foreignKey => $target_id)); } $Model->{$assoc_model}->updateAll(array($foreignKey => $target_id), array($foreignKey => $source_id)); break; default: return FALSE; } } // hasMany - default is both, options are : target,source,neither,both foreach ($Model->hasMany as $assoc_model => $assoc_setup) { $className = $assoc_setup['className']; $foreignKey = $assoc_setup['foreignKey']; $dependent = $assoc_setup['dependent']; if (!isset($assoc_options[$assoc_model]) && !isset($assoc_options['hasMany'][$assoc_model])) { $use = 'both'; // default behaviour } else { if (isset($assoc_options['hasMany']) && isset($assoc_options['hasMany'][$assoc_model])) { $use = $assoc_options['hasMany'][$assoc_model]; } else { $use = $assoc_options[$assoc_model]; } } switch ($use) { case 'both': $Model->{$assoc_model}->updateAll(array($foreignKey => $target_id), array($foreignKey => $source_id)); break; case 'neither': if ($dependent) { $Model->{$assoc_model}->deleteAll(array($foreignKey => array($source_id, $target_id))); } else { $Model->{$assoc_model}->updateAll(array($foreignKey => NULL), array($foreignKey => array($source_id, $target_id))); } break; case 'target': if ($dependent) { $Model->{$assoc_model}->deleteAll(array($foreignKey => array($source_id))); } else { $Model->{$assoc_model}->updateAll(array($foreignKey => NULL), array($foreignKey => $source_id)); } break; case 'source': if ($dependent) { $Model->{$assoc_model}->deleteAll(array($foreignKey => array($target_id))); } else { $Model->{$assoc_model}->updateAll(array($foreignKey => NULL), array($foreignKey => $target_id)); } $Model->{$assoc_model}->updateAll(array($foreignKey => $target_id), array($foreignKey => $source_id)); break; default: return FALSE; } } // HABTM - default is both, options are : target,source,neither,both foreach ($Model->hasAndBelongsToMany as $assoc_model => $assoc_setup) { $className = $assoc_setup['className']; $foreignKey = $assoc_setup['foreignKey']; //$assocForeignKey = $assoc_setup['associationForeignKey']; $joinModel = $Model->name . 's' . $className; if (!isset($assoc_options[$assoc_model]) && !isset($assoc_options['habtm'][$assoc_model])) { $use = 'both'; // default behaviour } else { if (isset($assoc_options['habtm']) && isset($assoc_options['habtm'][$assoc_model])) { $use = $assoc_options['habtm'][$assoc_model]; } else { $use = $assoc_options[$assoc_model]; } } switch ($use) { case 'both': $Model->{$joinModel}->updateAll(array($foreignKey => $target_id), array($foreignKey => $source_id)); break; case 'neither': $Model->{$joinModel}->deleteAll(array($foreignKey => array($source_id, $target_id))); break; case 'target': $Model->{$joinModel}->deleteAll(array($foreignKey => array($source_id))); break; case 'source': $Model->{$joinModel}->deleteAll(array($foreignKey => array($target_id))); $Model->{$joinModel}->updateAll(array($foreignKey => $target_id), array($foreignKey => $source_id)); break; default: return FALSE; } } $data = $target; $data[$Model->alias] = array_merge($data[$Model->alias], $new_values); if ($Model->save($data, false)) { $Model->delete($source_id, false); } return true; }
/** * @brief generates the cache the first time * @param (int) id - id of the event * @return (bool) */ public static function generate($id) { $event = Object::find($id); if ($event['repeating'] == 0) { return false; } $object = VObject::parse($event['calendardata']); $start = new \DateTime('01-01-' . date('Y') . ' 00:00:00', new \DateTimeZone('UTC')); $start->modify('-2 years'); $end = new \DateTime('31-12-' . date('Y') . ' 23:59:59', new \DateTimeZone('UTC')); $end->modify('+2 years'); $object->expand($start, $end); foreach ($object->getComponents() as $vevent) { if (!$vevent instanceof \Sabre\VObject\Component) { continue; } $startenddate = Object::generateStartEndDate($vevent->DTSTART, Object::getDTEndFromVEvent($vevent), $vevent->DTSTART->getValueType() == 'DATE' ? true : false, 'UTC'); $stmt = \OCP\DB::prepare('INSERT INTO `' . App::CldRepeatTable . '` (`eventid`,`calid`,`startdate`,`enddate`) VALUES(?,?,?,?)'); $stmt->execute(array($id, Object::getCalendarid($id), $startenddate['start'], $startenddate['end'])); } return true; }