예제 #1
0
 function saveWorkflow($values, $action, &$asset_controller)
 {
     if (!isset($values['page_content_id']) || !$values['page_content_id'] || !isset($values['workflow_group_id']) || !$values['workflow_group_id']) {
         return false;
     }
     // instantiate workflow model
     $model =& $this->getDefaultModel();
     $table = $model->table();
     // load values
     $page_content_id = $values['page_content_id'];
     $page_content_model =& NModel::factory('page_content');
     $page_content_model->get($page_content_id);
     $page_id = (int) $page_content_model->page_id;
     unset($page_content_model);
     $workflow_group_id = $values['workflow_group_id'];
     // timed content
     $timed_start = isset($values['timed_start']) && $values['timed_start'] ? $values['timed_start'] : null;
     $timed_end = isset($values['timed_end']) && $values['timed_end'] ? $values['timed_end'] : null;
     if ($timed_start == 'null') {
         $timed_start = null;
     }
     if ($timed_end == 'null') {
         $timed_end = null;
     }
     if ($timed_start && is_array($timed_start)) {
         $def = $table['timed_start'];
         $timed_start = NDate::arrayToDate($timed_start);
         if (!($def & N_DAO_NOTNULL)) {
             if (!NDate::validDateTime($timed_start)) {
                 $timed_start = false;
             }
         }
     }
     if ($timed_end && is_array($timed_end)) {
         $def = $table['timed_end'];
         $timed_end = NDate::arrayToDate($timed_end);
         if (!($def & N_DAO_NOTNULL)) {
             if (!NDate::validDateTime($timed_end)) {
                 $timed_end = false;
             }
         }
     }
     // load asset
     if (!$asset_controller) {
         return false;
     }
     $asset_model =& $asset_controller->getDefaultModel();
     if (!$asset_model) {
         return false;
     }
     $pk = $asset_model->primaryKey();
     $fields = $asset_model->fields();
     $values = array();
     foreach ($fields as $field) {
         if ($field != $pk && !preg_match('|^cms_|', $field)) {
             // don't save any of the meta content
             $values[$field] = $asset_model->{$field};
         }
     }
     $model->reset();
     $model->page_id = $page_id;
     $model->page_content_id = $page_content_id;
     $model->workflow_group_id = $workflow_group_id;
     $model->asset = $asset_controller->name;
     $model->asset_id = $asset_model->{$pk};
     $model->submitted = 0;
     $model->completed = 0;
     if ($timed_start) {
         $model->timed_start = $timed_start;
     }
     if ($timed_end) {
         $model->timed_end = $timed_end;
     }
     $model->cms_modified_by_user = $asset_controller->_auth->currentUserID();
     if ($model->find(null, true)) {
         $model->cms_modified = $model->now();
         $model->draft = serialize($values);
         $ret = $model->update();
     } else {
         $model->action = (int) $action;
         $model->draft = serialize($values);
         $model->cms_created = $model->now();
         $model->cms_modified = $model->now();
         $ret = $model->insert();
     }
     if (defined('SITE_AUDIT_TRAIL') && SITE_AUDIT_TRAIL) {
         $audit_trail =& NController::factory('audit_trail');
         $audit_trail->insert(array('asset' => $asset_controller->name, 'asset_id' => $asset_model->{$pk}, 'action_taken' => AUDIT_ACTION_WORKFLOW_START, 'workflow_id' => $model->{$model->primaryKey()}, 'workflow_group_id' => $workflow_group_id, 'page_id' => $page_id, 'page_content_id' => $page_content_id));
         unset($audit_trail);
     }
     unset($auth);
     unset($model);
     return $ret;
 }
 function addExistingContent($parameter)
 {
     $page_model =& $this->loadModel('page');
     $page_model->get($parameter);
     $template_container_id = isset($this->params['template_container_id']) ? $this->params['template_container_id'] : false;
     $asset = isset($this->params['asset']) ? $this->params['asset'] : false;
     // instantiate form
     include_once 'n_quickform.php';
     $form = new NQuickForm();
     $values = $form->getSubmitValues();
     $form->addElement('header', null, 'Add "' . Inflector::humanize($asset) . '" content to the "' . $page_model->title . '" page');
     $asset_controller =& NController::factory($asset);
     $asset_model =& NModel::factory($asset);
     $pk = $asset_model->primaryKey();
     $records = array();
     if ($asset_model->find()) {
         while ($asset_model->fetch()) {
             $records[$asset_model->{$pk}] = $asset_model->cms_headline;
         }
     }
     unset($asset_model);
     // add asset select
     $options = defined('SITE_WORKFLOW') && SITE_WORKFLOW ? array() : array('size' => 10, 'multiple' => 'multiple');
     $form->addElement('select', 'asset_id', Inflector::humanize($asset), $records, $options);
     // hidden fields
     $form->addElement('hidden', 'asset', $asset);
     $form->addElement('hidden', 'template_container_id', $template_container_id);
     if (isset($this->params['_referer'])) {
         $form->addElement('hidden', '_referer', urlencode($this->params['_referer']));
     }
     // finish up
     $form->addElement('submit', '__submit__', 'Add Content');
     // rules
     defined('SITE_WORKFLOW') && SITE_WORKFLOW ? $form->addRule('asset_id', 'You must select a record.', 'required') : $form->addGroupRule('asset_id', 'You must select a record.', 'required');
     $form->addRule('asset', '', 'required');
     $form->addRule('template_container_id', '', 'required');
     // check for workflow
     $user_rights = 0;
     if (SITE_WORKFLOW) {
         // get the users rights and bit compare them below
         $workflow =& NController::factory('workflow');
         $user_rights = $workflow->getWorkflowUserRights($page_model);
         if ($workflow_group_model =& $workflow->getWorkflowGroup($page_model)) {
             if (!($user_rights & WORKFLOW_RIGHT_EDIT)) {
                 // they don't belong here - go to the dashboard
                 header('Location:/' . APP_DIR . '/dashboard');
             } else {
                 if ($user_rights & WORKFLOW_RIGHT_EDIT) {
                     $form->insertElementBefore(NQuickForm::createElement('submit', '__submit_workflow__', 'Start Workflow'), '__submit__');
                     $form->removeElement('__submit__');
                 }
             }
         }
         unset($workflow);
     }
     $form->addElement('header', null, 'Make it timed content?');
     $timed_options = array('format' => 'Y-m-d H:i', 'minYear' => date('Y'), 'maxYear' => date('Y') + 4, 'addEmptyOption' => true);
     $form->addElement('date', 'timed_start', 'Timed Start', $timed_options);
     $form->addElement('date', 'timed_end', 'Timed End', $timed_options);
     if (!$user_rights) {
         $form->addElement('submit', '__submit_timed__', 'Add Scheduled Content');
     } else {
         $form->addElement('submit', '__submit_workflow__', 'Start Workflow with Scheduled Content');
     }
     if ($form->validate()) {
         $values = $form->exportValues();
         $model =& $this->loadModel($this->name);
         $workflow_active = false;
         if (SITE_WORKFLOW) {
             $workflow =& NController::factory('workflow');
             // check if this content is on any other page.
             // if it is, if either pages are part of a workflow group, we need to copy the content (go to addnewcontent with notice)
             // if neither do, then go ahead
             $asset_model =& $asset_controller->loadModel($asset_controller->name);
             $asset_model->get($values['asset_id']);
             $other_page =& $this->getContentPage($asset_controller);
             if ($other_page) {
                 $owned_content = false;
                 if ($workflow_group_model =& $workflow->getWorkflowGroup($page_model)) {
                     $owned_content = true;
                 } else {
                     if ($workflow_group_model =& $workflow->getWorkflowGroup($other_page)) {
                         $owned_content = true;
                     }
                 }
                 // if the content is already connected somewhere and one of the pages belongs to a workflow_group, then addNewContent with preloaded content
                 if ($owned_content) {
                     if (isset($values['__submit__'])) {
                         unset($values['__submit__']);
                     }
                     if (isset($values['__submit_workflow__'])) {
                         unset($values['__submit_workflow__']);
                     }
                     $this->redirectTo('copy_existing_content', $parameter, $values);
                     exit;
                 }
             }
             if (isset($values['__submit_workflow__']) && $values['__submit_workflow__']) {
                 $workflow =& NController::factory('workflow');
                 if ($workflow_group_model = $workflow->getWorkflowGroup($page_model)) {
                     $workflow_active = true;
                 }
             }
         }
         $model->page_id = $parameter;
         if (SITE_WORKFLOW && isset($values['__submit_workflow__']) && $values['__submit_workflow__']) {
             $model->cms_workflow = 1;
         }
         $model->page_template_container_id = $values['template_container_id'];
         $model->content_asset = $values['asset'];
         // set the timed values
         $timed_start = null;
         $timed_end = null;
         include_once 'n_date.php';
         if (isset($values['timed_start'])) {
             $timed_start = NDate::arrayToDate($values['timed_start']);
             $timed_start = NDate::convertTimeToUTC($timed_start);
             unset($values['timed_start']);
         }
         if (isset($values['timed_end'])) {
             $timed_end = NDate::arrayToDate($values['timed_end']);
             $timed_end = NDate::convertTimeToUTC($timed_end);
             unset($values['timed_end']);
         }
         if (!$workflow_active) {
             $table = $model->table();
             $def = $table['timed_start'];
             if (NDate::validDateTime($timed_start, $def)) {
                 $model->timed_start = $timed_start;
             } else {
                 $model->timed_start = N_DAO_NOTNULL & $def ? $timed_start : 'null';
             }
             $def = $table['timed_end'];
             if (NDate::validDateTime($timed_end, $def)) {
                 $model->timed_end = $timed_end;
             } else {
                 $model->timed_end = N_DAO_NOTNULL & $def ? $timed_end : 'null';
             }
         }
         $model->cms_created = $model->now();
         $model->cms_modified = $model->now();
         $model->cms_modified_by_user = $this->_auth->currentUserID();
         if (!is_array($values['asset_id'])) {
             $values['asset_id'] = array($values['asset_id']);
         }
         foreach ($values['asset_id'] as $asset_id) {
             $model->content_asset_id = $asset_id;
             $model->insert();
             if (defined('SITE_AUDIT_TRAIL') && SITE_AUDIT_TRAIL) {
                 // audit trail
                 $audit_trail =& NController::factory('audit_trail');
                 $audit_trail->insert(array('asset' => $asset_controller->name, 'asset_id' => $asset_id, 'action_taken' => AUDIT_ACTION_CONTENT_ADDEXISTING, 'page_content_id' => $model->{$model->primaryKey()}, 'page_id' => $model->page_id));
                 unset($audit_trail);
             }
         }
         if ($workflow_active) {
             $asset_controller =& NController::factory($values['asset']);
             $asset_controller->_auth = new NAuth();
             $asset_model =& $asset_controller->getDefaultModel();
             $asset_model->get($values['asset_id'][0]);
             $workflow_values = array();
             $workflow_values['page_content_id'] = $model->{$model->primaryKey()};
             $workflow_values['workflow_group_id'] = $workflow_group_model->{$workflow_group_model->primaryKey()};
             // add timed content
             $workflow_values['timed_start'] = $timed_start;
             $workflow_values['timed_end'] = $timed_end;
             $workflow->saveWorkflow($workflow_values, WORKFLOW_ACTION_ADDEXISTING, $asset_controller);
         }
         // delete the page cache
         $page =& NController::singleton('page');
         $page->deletePageCache($model->page_id);
         unset($page);
         // set up the referer
         if (isset($this->params['_referer']) && $this->params['_referer']) {
             $referer = urldecode($this->params['_referer']);
         } else {
             include_once 'view/helpers/url_helper.php';
             $referer = urlHelper::urlFor($this, array('controller' => 'page', 'action' => 'surftoedit', 'id' => $parameter));
         }
         header('Location:' . $referer);
         exit;
     }
     $this->auto_render = false;
     $this->page_title = 'Add Existing Content to "' . $page_model->title . '"';
     $this->set(array('title' => 'Select Content', 'form' => $form->toHTML()));
     $this->render(array('action' => 'form', 'layout' => 'plain'));
     unset($page_model);
 }
예제 #3
0
 function exportValues($element_list = null)
 {
     $vals = $this->form->exportValues($element_list);
     $fields = $this->model->table();
     foreach ($vals as $field => $val) {
         if (!isset($fields[$field])) {
             continue;
         }
         $def = $fields[$field];
         switch (true) {
             case $def & N_DAO_DATE:
             case $def & N_DAO_TIME:
                 if (is_array($vals[$field])) {
                     $vals[$field] = NDate::arrayToDate($vals[$field]);
                 }
         }
     }
     return $vals;
 }