MODULE = 'bx_tasks'; parent::__construct($aInfo, $oTemplate); $CNF = &$this->_oModule->_oConfig->CNF; if(isset($CNF['FIELD_COVER']) && isset($this->aInputs[$CNF['FIELD_COVER']])) { if($this->_oModule->checkAllowedSetThumb() === CHECK_ACTION_RESULT_ALLOWED) { $this->aInputs[$CNF['FIELD_COVER']]['storage_object'] = $CNF['OBJECT_STORAGE']; $this->aInputs[$CNF['FIELD_COVER']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_COVER']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_COVER']]['value']) : $CNF['OBJECT_UPLOADERS']; $this->aInputs[$CNF['FIELD_COVER']]['upload_buttons_titles'] = array( 'Simple' => _t('_bx_tasks_form_entry_input_covers_uploader_simple_title'), 'HTML5' => _t('_bx_tasks_form_entry_input_covers_uploader_html5_title') ); $this->aInputs[$CNF['FIELD_COVER']]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']; $this->aInputs[$CNF['FIELD_COVER']]['storage_private'] = 0; $this->aInputs[$CNF['FIELD_COVER']]['multiple'] = false; $this->aInputs[$CNF['FIELD_COVER']]['content_id'] = 0; $this->aInputs[$CNF['FIELD_COVER']]['ghost_template'] = ''; } else unset($this->aInputs[$CNF['FIELD_COVER']]); } if(isset($CNF['FIELD_PHOTO']) && isset($this->aInputs[$CNF['FIELD_PHOTO']])) { $this->aInputs[$CNF['FIELD_PHOTO']]['storage_object'] = $CNF['OBJECT_STORAGE_PHOTOS']; $this->aInputs[$CNF['FIELD_PHOTO']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_PHOTO']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_PHOTO']]['value']) : $CNF['OBJECT_UPLOADERS']; $this->aInputs[$CNF['FIELD_PHOTO']]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']; $this->aInputs[$CNF['FIELD_PHOTO']]['storage_private'] = 0; $this->aInputs[$CNF['FIELD_PHOTO']]['multiple'] = true; $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'] = 0; $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = ''; $this->aInputs[$CNF['FIELD_PHOTO']]['tr_attrs'] = array('class'=> 'bx-base-text-attachment-item'); } if(isset($this->aInputs[$CNF['FIELD_VIDEO']])) { $this->aInputs[$CNF['FIELD_VIDEO']]['storage_object'] = $CNF['OBJECT_STORAGE_VIDEOS']; $this->aInputs[$CNF['FIELD_VIDEO']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_VIDEO']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_VIDEO']]['value']) : $CNF['OBJECT_UPLOADERS']; $this->aInputs[$CNF['FIELD_VIDEO']]['images_transcoder'] = $CNF['OBJECT_VIDEOS_TRANSCODERS']['poster_preview']; $this->aInputs[$CNF['FIELD_VIDEO']]['storage_private'] = 0; $this->aInputs[$CNF['FIELD_VIDEO']]['multiple'] = true; $this->aInputs[$CNF['FIELD_VIDEO']]['content_id'] = 0; $this->aInputs[$CNF['FIELD_VIDEO']]['ghost_template'] = ''; $this->aInputs[$CNF['FIELD_VIDEO']]['tr_attrs'] = array('class'=> 'bx-base-text-attachment-item'); } if (isset($CNF['FIELD_FILE']) && isset($this->aInputs[$CNF['FIELD_FILE']])) { $this->aInputs[$CNF['FIELD_FILE']]['storage_object'] = $CNF['OBJECT_STORAGE_FILES']; $this->aInputs[$CNF['FIELD_FILE']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_FILE']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_FILE']]['value']) : $CNF['OBJECT_UPLOADERS']; $this->aInputs[$CNF['FIELD_FILE']]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES']; $this->aInputs[$CNF['FIELD_FILE']]['storage_private'] = 0; $this->aInputs[$CNF['FIELD_FILE']]['multiple'] = true; $this->aInputs[$CNF['FIELD_FILE']]['content_id'] = 0; $this->aInputs[$CNF['FIELD_FILE']]['ghost_template'] = ''; $this->aInputs[$CNF['FIELD_FILE']]['tr_attrs'] = array('class'=> 'bx-base-text-attachment-item'); } if (isset($this->aInputs['initial_members']) && !isset($this->aInputs['initial_members']['value'])) { if (bx_get('id')){ $oConn = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION']); $this->aInputs['initial_members']['value'] = $oConn->getConnectedInitiators(bx_get('id')); } else{ $this->aInputs['initial_members']['value'] = array(bx_get_logged_profile_id()); } } } function getCode($bDynamicMode = false) { $this->_replaceMarkersInControls('controls_edit'); $sResult = parent::getCode($bDynamicMode); $sInclude = $this->_oModule->_oTemplate->addJs(array('tasks.js'), $bDynamicMode); $sResult .= ($bDynamicMode ? $sInclude : '') . $this->_oModule->_oTemplate->getJsCode('tasks'); return $sResult; } function initChecker ($aValues = array (), $aSpecificValues = array()) { $CNF = &$this->_oModule->_oConfig->CNF; $bValues = $aValues && !empty($aValues['id']); $aContentInfo = $bValues ? $this->_oModule->_oDb->getContentInfoById($aValues['id']) : false; if($this->aParams['display'] == $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'] && isset($CNF['FIELD_PUBLISHED']) && isset($this->aInputs[$CNF['FIELD_PUBLISHED']])) if($bValues && in_array($aValues[$CNF['FIELD_STATUS']], array('active', 'hidden'))) unset($this->aInputs[$CNF['FIELD_PUBLISHED']]); if (isset($CNF['FIELD_COVER']) && isset($this->aInputs[$CNF['FIELD_COVER']])) { if($bValues) $this->aInputs[$CNF['FIELD_COVER']]['content_id'] = $aValues['id']; $this->aInputs[$CNF['FIELD_COVER']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateCover, $this->_getCoverGhostTmplVars($aContentInfo)); } parent::initChecker ($aValues, $aSpecificValues); } public function insert ($aValsToAdd = array(), $isIgnore = false) { $CNF = &$this->_oModule->_oConfig->CNF; if(isset($CNF['FIELD_ADDED']) && empty($aValsToAdd[$CNF['FIELD_ADDED']])) { $iAdded = 0; if(isset($this->aInputs[$CNF['FIELD_ADDED']])) $iAdded = $this->getCleanValue($CNF['FIELD_ADDED']); if(empty($iAdded)) $iAdded = time(); $aValsToAdd[$CNF['FIELD_ADDED']] = $iAdded; } if(empty($aValsToAdd[$CNF['FIELD_PUBLISHED']])) { $iPublished = 0; if(isset($this->aInputs[$CNF['FIELD_PUBLISHED']])) $iPublished = $this->getCleanValue($CNF['FIELD_PUBLISHED']); if(empty($iPublished)) $iPublished = time(); $aValsToAdd[$CNF['FIELD_PUBLISHED']] = $iPublished; } $aValsToAdd[$CNF['FIELD_STATUS']] = $aValsToAdd[$CNF['FIELD_PUBLISHED']] > $aValsToAdd[$CNF['FIELD_ADDED']] ? 'awaiting' : 'active'; $iContentId = parent::insert ($aValsToAdd, $isIgnore); if(!empty($iContentId)){ $this->processFiles($CNF['FIELD_COVER'], $iContentId, true); if(isset($this->aInputs['initial_members'])) { $this->_setAssignments($iContentId, $this->aInputs['initial_members']['value']); } } return $iContentId; } function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null) { $CNF = &$this->_oModule->_oConfig->CNF; if(empty($aValsToAdd[$CNF['FIELD_PUBLISHED']]) && isset($this->aInputs[$CNF['FIELD_PUBLISHED']])) { $iPublished = $this->getCleanValue($CNF['FIELD_PUBLISHED']); if(empty($iPublished)) $iPublished = time(); $aValsToAdd[$CNF['FIELD_PUBLISHED']] = $iPublished; } if(isset($this->aInputs['initial_members'])) { $this->_setAssignments($iContentId, $this->aInputs['initial_members']['value']); } $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId); $aValsToAdd[$CNF['FIELD_ALLOW_VIEW_TO']] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]; $iResult = parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges); $this->processFiles($CNF['FIELD_COVER'], $iContentId, false); return $iResult; } protected function _getCoverGhostTmplVars($aContentInfo = array()) { $CNF = &$this->_oModule->_oConfig->CNF; return array ( 'name' => $this->aInputs[$CNF['FIELD_COVER']]['name'], 'content_id' => $this->aInputs[$CNF['FIELD_COVER']]['content_id'], 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '', 'thumb_id' => isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : 0, 'name_thumb' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : '' ); } protected function _getPhotoGhostTmplVars($aContentInfo = array()) { $CNF = &$this->_oModule->_oConfig->CNF; return array ( 'name' => $this->aInputs[$CNF['FIELD_PHOTO']]['name'], 'content_id' => (int)$this->aInputs[$CNF['FIELD_PHOTO']]['content_id'], 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '', 'bx_if:set_thumb' => [ 'condition' => false, 'content' => [] ], ); } protected function _setAssignments($iContentId, $aMembers) { $CNF = &$this->_oModule->_oConfig->CNF; $oConn = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION']); $aMembers2 = $oConn->getConnectedInitiators($iContentId); $aMembersToAdd = []; $aMembersToRemove = $aMembers2; if (is_array($aMembers)){ $aMembersToAdd = array_diff($aMembers, $aMembers2); $aMembersToRemove = array_diff($aMembers2, $aMembers); } $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId); foreach($aMembersToAdd as $iProfileId){ $oConn->addConnection($iProfileId, $iContentId); /** * @hooks * @hookdef hook-bx_tasks-assigned 'bx_tasks', 'assigned' - hook on task assigned to profile * - $unit_name - equals `bx_tasks` * - $action - equals `assigned` * - $object_id - task id * - $sender_id - not used * - $extra_params - array of additional params with the following array keys: * - `object_author_id` - [int] id for assigned profile * - `privacy_view` - [string] privacy view value * @hook @ref hook-bx_tasks-assigned */ bx_alert($this->MODULE, 'assigned', $iContentId, false, array( 'object_author_id' => $iProfileId, 'privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] )); } foreach($aMembersToRemove as $iProfileId){ $oConn->removeConnection($iProfileId, $iContentId); /** * @hooks * @hookdef hook-bx_tasks-unassigned 'bx_tasks', 'unassigned' - hook on task unassigned to profile * - $unit_name - equals `bx_tasks` * - $action - equals `unassigned` * - $object_id - task id * - $sender_id - not used * - $extra_params - array of additional params with the following array keys: * - `object_author_id` - [int] id for unassigned profile * - `privacy_view` - [string] privacy view value * @hook @ref hook-bx_tasks-unassigned */ bx_alert($this->MODULE, 'unassigned', $iContentId, false, array( 'object_author_id' => $iProfileId, 'privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] )); } } protected function genCustomInputInitialMembers ($aInput) { $aInput['ajax_get_suggestions'] = BX_DOL_URL_ROOT . "modules/?r=" . $this->_oModule->_oConfig->getUri() . "/ajax_get_initial_members"; return $this->genCustomInputUsernamesSuggestions($aInput); } protected function genCustomInputTasksList(&$aInput) { return $this->genInputStandard($aInput); } } /** @} */