/** * Overwrite save to set the uri if it's not already set and recalculate the minutes. */ public function save() { // Prevent http://jira.opensource.mayflower.de/jira/browse/PHPROJEKT-450 if (is_null($this->notes)) { $this->notes = ''; } if (empty($this->endTime)) { $this->minutes = null; } else { $start = new Datetime($this->startDatetime); $end = new Datetime(substr($this->startDatetime, 0, 11) . $this->endTime); $this->minutes = floor(($end->getTimestamp() - $start->getTimestamp()) / 60); } if (empty($this->uid)) { $this->uid = Phprojekt::generateUniqueIdentifier(); } if (empty($this->uri)) { $this->uri = $this->uid; } if (!$this->projectId) { $this->projectId = 1; } return parent::save(); }
/** * Use directly the the Abstract Record to don't save the history or search words. * * @return void */ public function parentSave() { return parent::save(); }
/** * Saves a frontend message to the database using the abstract record pattern. * * Since the actor id is allways the user who calls this method, the actor_id will be set here. * * @return boolean True on a sucessful save. */ public function saveFrontendMessage() { $return = ''; $this->actorId = (int) Phprojekt_Auth::getUserId(); if (false === is_array($this->recipientId)) { $return = parent::save(); } else { $recipient = $this->recipientId; foreach ($recipient as $id) { $model = clone $this; $model->actorId = $this->actorId; $model->projectId = $this->projectId; $model->itemId = $this->itemId; $model->process = $this->process; $model->validUntil = $this->validUntil; $model->validFrom = $this->validFrom; $model->moduleId = $this->moduleId; $model->description = $this->description; $model->details = $this->details; $model->recipientId = $id; $model->itemName = $this->itemName; $return = $model->save(); } } return $return; }
/** * Save is handled by parent. * * @return boolean True for a sucessful save. */ public function save() { $db = $this->getAdapter(); if (trim($this->sortOrder) == '' || is_null($this->sortOrder) || !$this->sortOrder) { // We don't have a sort order yet, most probably a brand-new record. // Detect highest available sort order up until now and use next-higher number. $sql = 'SELECT MAX(' . $db->quoteIdentifier('sort_order') . ') FROM ' . $db->quoteIdentifier($this->getTableName()) . ' WHERE ' . $db->quoteIdentifier('minutes_id') . ' = ?'; $result = $db->fetchCol($sql, $this->_minutesId); $maxSort = $result[0]; if (!$maxSort || $maxSort < 0) { $maxSort = 0; } $this->sortOrder = $maxSort + 1; } elseif (is_numeric($this->sortOrder) && $this->sortOrder > 0) { if (!isset($this->_history['sortOrder']) || isset($this->_history['sortOrder']) && $this->_history['sortOrder'] != $this->sortOrder) { // A sort order was given and differs from the initial value. We need to increment // all sort order values equal or above the new value by one, and then update this // record with the new value. That should ensure order value consistency. $data = array('sort_order' => new Zend_Db_Expr($this->_db->quoteIdentifier('sort_order') . ' + 1')); $where = sprintf('%s = %d and %s >= %d', $this->_db->quoteIdentifier('minutes_id'), $this->_minutesId, $this->_db->quoteIdentifier('sort_order'), $this->sortOrder); $this->update($data, $where); } } return parent::save(); }
/** * Extencion of the ActiveRecord save adding default permissions. * * @return boolean True for a sucessful save. */ public function save() { if ($this->id == 0) { if (parent::save()) { // adding default values $rights = new Phprojekt_Item_Rights(); $rights->saveDefaultRights($this->id); return true; } } else { return parent::save(); } }
/** * Extension of save() for don't save the search strings. * Only allow save if the contact is public or the ownerId is the current user. * * @return void */ public function save() { $result = true; if (!$this->private || $this->private && $this->ownerId == Phprojekt_Auth::getUserId()) { if ($this->id > 0) { $this->_history->saveFields($this, 'edit'); $result = Phprojekt_ActiveRecord_Abstract::save(); } else { $result = Phprojekt_ActiveRecord_Abstract::save(); $this->_history->saveFields($this, 'add'); } } return $result; }
/** * Extencion of the ActiveRecord save adding default permissions. * * @return boolean True for a sucessful save. */ public function save() { // Reset users by project cache $activeRecord = Phprojekt_Loader::getModel('Project', 'Project'); $tree = new Phprojekt_Tree_Node_Database($activeRecord, 1); $tree = $tree->setup(); foreach ($tree as $node) { $sessionName = 'Phprojekt_User_User-getAllowedUsers' . '-' . (int) $node->id; $namespace = new Zend_Session_Namespace($sessionName); if (isset($namespace->users)) { $namespace->unsetAll(); } } if ($this->id == 0) { if (parent::save()) { // adding default values $rights = Phprojekt_Loader::getLibraryClass('Phprojekt_Item_Rights'); $rights->saveDefaultRights($this->id); return true; } } else { return parent::save(); } }