예제 #1
0
 /**
  * Validate the data of the current record.
  *
  * @return boolean True for valid.
  */
 public function recordValidate()
 {
     if (!$this->_validate->validateDateRange($this->startDate, $this->endDate)) {
         return false;
     } else {
         return parent::recordValidate();
     }
 }
예제 #2
0
 /**
  * Save the display data, insert or update.
  *
  * @param Phprojekt_Item_Abstract $object   The item object.
  * @param integer                 $moduleId The module ID to store.
  * @param integer                 $itemId   The item ID to store.
  *
  * @return void
  */
 public function saveDisplay($object, $moduleId, $itemId)
 {
     $firstDisplay = '';
     $secondDisplay = '';
     $firstField = $object->searchFirstDisplayField;
     $secondField = $object->searchSecondDisplayField;
     $projectId = $object->projectId;
     if ($object->hasField($firstField)) {
         $firstDisplay = $object->{$firstField};
     } else {
         $firstDisplay = "ID: " . $object->id;
     }
     if ($object->hasField($secondField)) {
         $secondDisplay = $object->{$secondField};
         if (strlen($secondDisplay) > 100) {
             $secondDisplay = substr($secondDisplay, 0, 100) . "...";
         }
     }
     if (!$this->_exists($moduleId, $itemId)) {
         $this->_save($moduleId, $itemId, $projectId, $firstDisplay, $secondDisplay);
     } else {
         $this->_update($moduleId, $itemId, $projectId, $firstDisplay, $secondDisplay);
     }
 }
예제 #3
0
 /**
  * Save the rights for the current item.
  *
  * The users are a POST array with user IDs.
  *
  * @param array $rights Array of user IDs with the bitmask access.
  *
  * @return void
  */
 public function saveRights($rights)
 {
     // Do the default action
     parent::saveRights($rights);
     // Update access and delete the cache also for the children
     $itemRights = Phprojekt_Loader::getLibraryClass('Phprojekt_Item_Rights');
     $activeRecord = Phprojekt_Loader::getModel('Project', 'Project');
     $tree = new Phprojekt_Tree_Node_Database($activeRecord, $this->id);
     $tree = $tree->setup();
     $users = array();
     foreach ($rights as $userId => $access) {
         $users[] = (int) $userId;
     }
     // Just a check
     if (empty($users)) {
         $users[] = 1;
     }
     // Keep on the childen only the access for the allowed users in the parent
     foreach ($tree as $node) {
         $projectId = (int) $node->id;
         // Delete users that are not allowed in the parent
         $where = sprintf('module_id = 1 AND item_id = %d AND user_id NOT IN (%s)', $projectId, implode(",", $users));
         $itemRights->delete($where);
         // Reset access by module-item-user
         foreach ($users as $userId) {
             // Reset cache
             $sessionName = 'Phprojekt_Item_Rights-getItemRight' . '-1-' . $projectId . '-' . $userId;
             $rightNamespace = new Zend_Session_Namespace($sessionName);
             $rightNamespace->unsetAll();
         }
         // Reset access by module-item
         $sessionName = 'Phprojekt_Item_Rights-getUsersRights' . '-1-' . $projectId;
         $rightNamespace = new Zend_Session_Namespace($sessionName);
         $rightNamespace->unsetAll();
         // Reset users by module-item
         $sessionName = 'Phprojekt_Item_Rights-getUsersWithRight' . '-1-' . $projectId;
         $rightNamespace = new Zend_Session_Namespace($sessionName);
         $rightNamespace->unsetAll();
         // Reset users by project
         $sessionName = 'Phprojekt_User_User-getAllowedUsers' . '-' . $projectId;
         $rightNamespace = new Zend_Session_Namespace($sessionName);
         $rightNamespace->unsetAll();
     }
 }
예제 #4
0
 /**
  * Customized version to calculate the status of a minutes item regardless of its saved database entry.
  *
  * @param string|array $where  Where clause.
  * @param string|array $order  Order by.
  * @param string|array $count  Limit query.
  * @param string|array $offset Query offset.
  * @param string       $select The comma-separated columns of the joined columns.
  * @param string       $join   The join statements.
  *
  * @return Zend_Db_Table_Rowset The rowset with the results.
  */
 public function fetchAll($where = null, $order = null, $count = null, $offset = null, $select = null, $join = null)
 {
     $result = parent::fetchAll($where, $order, $count, $offset, $select, $join);
     return array_map(array($this, '_calcStatus'), $result);
 }
예제 #5
0
 /**
  * Validate the data of the current record.
  *
  * @return boolean True for valid.
  */
 public function recordValidate()
 {
     // one is the unique value available because calendar is a global module
     if (Phprojekt_Module::getSaveType(Phprojekt_Module::getId($this->getModelName())) >= 1) {
         $this->projectId = 1;
     }
     if (strtotime($this->startDatetime) >= strtotime($this->endDatetime)) {
         $this->_validate->error->addError(array('field' => "Event duration", 'label' => Phprojekt::getInstance()->translate('Event duration'), 'message' => Phprojekt::getInstance()->translate('End date and time has to be after Start date and ' . 'time')));
         return false;
     }
     return parent::recordValidate();
 }
예제 #6
0
 /**
  * Implemented because we need to reset the participant data.
  */
 public function __clone()
 {
     parent::__clone();
     $this->_participantData = null;
     $this->_participantDataInDb = null;
     $this->_originalStart = null;
     $this->_isFirst = true;
 }
예제 #7
0
 /**
  * Validate the data of the current record.
  *
  * @return boolean True for valid.
  */
 public function recordValidate()
 {
     if (strtotime($this->startDatetime) >= strtotime($this->endDatetime)) {
         $this->_validate->error->addError(array('field' => "Event duration", 'label' => Phprojekt::getInstance()->translate('Event duration'), 'message' => Phprojekt::getInstance()->translate('End date and time has to be after Start date and ' . 'time')));
         return false;
     }
     return parent::recordValidate();
 }
예제 #8
0
 /**
  * Extension of getUsersRights() for use the parent minute getUsersRights();
  *
  * @return array Array with rights.
  */
 public function getUsersRights()
 {
     return $this->_minutes->getUsersRights();
 }
예제 #9
0
 /**
  * Extension of delete() for don't save the search strings.
  * Only allow delete if the contact is public or the ownerId is the current user.
  *
  * @return void
  */
 public function delete()
 {
     if (!$this->private || $this->private && $this->ownerId == Phprojekt_Auth::getUserId()) {
         $this->deleteUploadFiles();
         $this->_history->saveFields($this, 'delete');
         parent::delete();
     }
 }
예제 #10
0
 /**
  * Delete all the entries for one object.
  *
  * @param Phprojekt_Item_Abstract $object The item object.
  *
  * @return void
  */
 public function deleteObjectItem($object)
 {
     $moduleId = Phprojekt_Module::getId($object->getModelName());
     $itemId = $object->id;
     $wordsId = $this->_wordModule->deleteWords($moduleId, $itemId);
     $this->_words->decreaseWords($wordsId);
     $this->_display->deleteDisplay($moduleId, $itemId);
 }
예제 #11
0
 /**
  * Returns the last changes, if there are any, for a specific module and item id.
  *
  * The result data is used by Mail_Notification class, when telling the users related
  * to an item that it has been modified.
  *
  * @param Phprojekt_Item_Abstract $object The item object
  *
  * @return array Array with 'userId', 'moduleId', 'itemId', 'field', 'label',
  *                          'oldValue', 'newValue', 'action' and 'datetime'.
  */
 public function getLastHistoryData($object)
 {
     $result = array();
     $moduleId = Phprojekt_Module::getId($object->getModelName());
     $itemId = $object->id;
     $where = sprintf('module_id = %d AND item_id = %d', (int) $moduleId, (int) $itemId);
     $datetime = null;
     $action = null;
     $history = $this->fetchAll($where, 'id DESC');
     $stop = false;
     foreach ($history as $row) {
         if (!$stop) {
             if (null === $datetime) {
                 $datetime = $row->datetime;
                 $action = $row->action;
             }
             if ($action == $row->action) {
                 $diff = abs(strtotime($datetime) - strtotime($row->datetime));
                 if ($diff < 1) {
                     $result[] = array('userId' => $row->userId, 'moduleId' => $row->moduleId, 'itemId' => $row->itemId, 'field' => $row->field, 'oldValue' => $row->oldValue, 'newValue' => $row->newValue, 'action' => $row->action, 'datetime' => $row->datetime);
                 } else {
                     $stop = true;
                     break;
                 }
             } else {
                 $stop = true;
                 break;
             }
         }
     }
     return array_reverse($result);
 }
예제 #12
0
 /**
  * Check the current Fields and make the sync in the table of the module.
  *
  * @param array  $newFields Array with all the data per new field.
  * @param string $tableName Name of the module Table.
  * @param array  $tableData Array with the table data definition per new field.
  *
  * @return boolean True on a sucessful sync.
  */
 public function syncTable($newFields, $tableName, $tableData)
 {
     $systemFields = array('id', 'owner_id', 'project_id');
     $tableManager = new Phprojekt_Table(Phprojekt::getInstance()->getDb());
     // Clean the metadata cache
     if (null !== $this->_model) {
         $info = $this->_model->info();
         $dbConfig = Phprojekt::getInstance()->getDb()->getConfig();
         // Define the cache identifier where the metadata are saved
         $cacheId = md5((isset($dbConfig['options']['port']) ? ':' . $dbConfig['options']['port'] : null) . (isset($dbConfig['options']['host']) ? ':' . $dbConfig['options']['host'] : null) . '/' . $dbConfig['dbname'] . ':' . $info['schema'] . '.' . $info['name']);
         Zend_Db_Table_Abstract::getDefaultMetadataCache()->remove($cacheId);
     }
     $oldFields = $this->getDataDefinition();
     $tableDataForCreate['id'] = array('type' => 'auto_increment', 'length' => 11);
     $tableDataForCreate['owner_id'] = array('type' => 'int', 'length' => 11);
     if (!isset($tableDataForCreate['project_id'])) {
         $tableDataForCreate['project_id'] = array('type' => 'int', 'length' => 11);
     }
     array_merge($tableDataForCreate, $tableData);
     $tableName = strtolower(self::convertTableField($tableName));
     $tableFields = $tableManager->getTableFields($tableName, $tableDataForCreate);
     // Search for Modify and Delete
     $return = true;
     foreach ($oldFields as $oldValues) {
         $found = false;
         foreach ($newFields as $newValues) {
             if ($oldValues['id'] == $newValues['id']) {
                 $newValues['tableField'] = self::convertTableField($newValues['tableField']);
                 $fieldDefinition = $tableData[$newValues['tableField']];
                 $fieldDefinition['name'] = $newValues['tableField'];
                 if (!in_array($fieldDefinition['name'], $systemFields)) {
                     if ($oldValues['tableField'] == $newValues['tableField']) {
                         if (!$tableManager->modifyField($tableName, $fieldDefinition)) {
                             $return = false;
                         }
                     } else {
                         $fieldDefinition['oldName'] = $oldValues['tableField'];
                         if (!$tableManager->changeField($tableName, $fieldDefinition)) {
                             $return = false;
                         }
                     }
                 }
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             $fieldDefinition = array();
             $fieldDefinition['name'] = $oldValues['tableField'];
             if (!in_array($fieldDefinition['name'], $systemFields)) {
                 if (!$tableManager->deleteField($tableName, $fieldDefinition)) {
                     $return = false;
                 }
             }
         }
     }
     // Search for Add
     foreach ($newFields as $newValues) {
         if ($newValues['id'] == 0) {
             $newValues['tableField'] = self::convertTableField($newValues['tableField']);
             $fieldDefinition = $tableData[$newValues['tableField']];
             $fieldDefinition['name'] = $newValues['tableField'];
             if (!in_array($fieldDefinition['name'], $systemFields)) {
                 if (!$tableManager->addField($tableName, $fieldDefinition)) {
                     $return = false;
                 }
             }
         }
     }
     return $return;
 }
예제 #13
0
 /**
  * Delete all the entries for one object.
  *
  * @param Phprojekt_Item_Abstract $object The item object.
  *
  * @return void
  */
 public function deleteObjectItem($object)
 {
     $moduleId = Phprojekt_Module::getId($object->getModelName());
     $itemId = $object->id;
     $this->deleteObjectItemByIds($moduleId, $itemId);
 }
예제 #14
0
 /**
  * Set the parent related minutes object.
  *
  * @param integer $minutesId Parent minute ID.
  *
  * @return void
  */
 public function setParent($minutesId)
 {
     $this->_minutes = new Minutes_Models_Minutes();
     $this->_minutes = $this->_minutes->find($minutesId);
 }
예제 #15
0
 public function recordValidate()
 {
     return parent::recordValidate() && $this->_validateFilenamesAreUnique();
 }