コード例 #1
0
	public function review_entries()
	{	
		$EE =& get_instance();
		$EE->lang->loadfile('nsm_pp_workflow');
		
		if(!class_exists('Nsm_pp_workflow_model')){
			include(dirname(__FILE__).'/models/nsm_pp_workflow_model.php');
		}
		
		if(!$this->settings){
			// get extension settings
			if(!class_exists('Nsm_pp_workflow_ext')){
				include(dirname(__FILE__).'/ext.nsm_pp_workflow.php');
			}
			$nsm_pp_ext = new Nsm_pp_workflow_ext();
			$this->settings = $nsm_pp_ext->settings;
		}
		
		$channel_ids = $this->_returnChannelIDs($this->settings);
		if(!count($channel_ids)){
			// no channels set
			return array('error', $EE->lang->line('nsm_pp_workflow_review_entries_no_channels'));
		}
		
		$entries = Nsm_pp_workflow_model::findByReviewNow($channel_ids);
		if(count($entries) == 0){
			// returned no entries, tell user
			return array('success', $EE->lang->line('nsm_pp_workflow_review_entries_db_select_none'));
		}elseif(!$entries){
			// returned false, error
			return array('error', $EE->lang->line('nsm_pp_workflow_review_entries_db_select_error'));
		}
		
		$entry_ids = Nsm_pp_workflow_model::getCollectionEntryIds($entries);
		
		//$updates = true;
		$updates = Nsm_pp_workflow_model::updateEntryState($channel_ids);
		if(!$updates){
			return array('error', $EE->lang->line('nsm_pp_workflow_review_entries_db_update_error'));
		}
		
		$notification_status = $this->_processNotifications($entry_ids);
		if($notification_status['sent'] == $notification_status['pending']){
			$message = sprintf(
							$EE->lang->line('nsm_pp_workflow_review_entries_ok'), 
							$notification_status['sent'],
							$notification_status['pending']
						);
			return array('success', $message);
		}else{
			$message = sprintf(
							$EE->lang->line('nsm_pp_workflow_review_entries_email_error'), 
							$notification_status['sent'],
							$notification_status['pending']
						);
			return array('success', $message);
		}
	}