} if (isset($project_templates) && !is_null($project_templates)) { foreach($project_templates as $template) { $project_templates_array[] = $template->getArrayInfo(); } } if (isset($tasks)) { $ids = array(); foreach($tasks as $task) { $ids[] = $task['id']; $tasks_array[] = ProjectTasks::getArrayInfo($task); } $read_objects = ReadObjects::getReadByObjectList($ids, logged_user()->getId()); foreach($tasks_array as &$data) { $data['isread'] = isset($read_objects[$data['id']]); } } if (is_array($internalMilestones)) { foreach($internalMilestones as $milestone) { $internal_milestones_array[] = $milestone->getArrayInfo(); } } if (is_array($externalMilestones)) { foreach($externalMilestones as $milestone) { $external_milestones_array[] = $milestone->getArrayInfo(); }
function list_all() { ajx_current("empty"); $context = active_context(); $start = array_var($_GET, 'start', 0); $limit = array_var($_GET, 'limit', config_option('files_per_page')); $order = array_var($_GET, 'sort'); if ($order == "updatedOn" || $order == "updated" || $order == "date" || $order == "dateUpdated") { $order = "updated_on"; } $order_dir = array_var($_GET, 'dir'); $page = (int) ($start / $limit) + 1; $hide_private = !logged_user()->isMemberOfOwnerCompany(); if (array_var($_GET, 'action') == 'delete') { $ids = explode(',', array_var($_GET, 'webpages')); $succ = 0; $err = 0; foreach ($ids as $id) { $web_page = ProjectWebpages::findById($id); if (isset($web_page) && $web_page->canDelete(logged_user())) { try { DB::beginWork(); $web_page->trash(); ApplicationLogs::createLog($web_page, ApplicationLogs::ACTION_TRASH); DB::commit(); $succ++; } catch (Exception $e) { DB::rollback(); $err++; } } else { $err++; } } if ($succ > 0) { flash_success(lang("success delete objects", $succ)); } if ($err > 0) { flash_error(lang("error delete objects", $err)); } } else { if (array_var($_GET, 'action') == 'markasread') { $ids = explode(',', array_var($_GET, 'ids')); $succ = 0; $err = 0; foreach ($ids as $id) { $webpage = ProjectWebpages::findById($id); try { $webpage->setIsRead(logged_user()->getId(), true); $succ++; } catch (Exception $e) { $err++; } } if ($succ <= 0) { flash_error(lang("error markasread files", $err)); } } else { if (array_var($_GET, 'action') == 'markasunread') { $ids = explode(',', array_var($_GET, 'ids')); $succ = 0; $err = 0; foreach ($ids as $id) { $webpage = ProjectWebpages::findById($id); try { $webpage->setIsRead(logged_user()->getId(), false); $succ++; } catch (Exception $e) { $err++; } } if ($succ <= 0) { flash_error(lang("error markasunread files", $err)); } } else { if (array_var($_GET, 'action') == 'archive') { $ids = explode(',', array_var($_GET, 'webpages')); $succ = 0; $err = 0; foreach ($ids as $id) { $web_page = ProjectWebpages::findById($id); if (isset($web_page) && $web_page->canEdit(logged_user())) { try { DB::beginWork(); $web_page->archive(); ApplicationLogs::createLog($web_page, ApplicationLogs::ACTION_ARCHIVE); DB::commit(); $succ++; } catch (Exception $e) { DB::rollback(); $err++; } } else { $err++; } } if ($succ > 0) { flash_success(lang("success archive objects", $succ)); } if ($err > 0) { flash_error(lang("error archive objects", $err)); } } } } } $res = ProjectWebpages::instance()->listing(array("order" => $order, "order_dir" => $order_dir)); $object = array("totalCount" => $res->total, "start" => $start, "webpages" => array()); if (isset($res->objects)) { $index = 0; $ids = array(); foreach ($res->objects as $w) { $ids[] = $w->getId(); $object["webpages"][] = array("ix" => $index++, "id" => $w->getId(), "object_id" => $w->getObjectId(), "ot_id" => $w->getObjectTypeId(), "name" => $w->getObjectName(), "description" => $w->getDescription(), "url" => $w->getUrl(), "updatedOn" => $w->getUpdatedOn() instanceof DateTimeValue ? $w->getUpdatedOn()->isToday() ? format_time($w->getUpdatedOn()) : format_datetime($w->getUpdatedOn()) : '', "updatedOn_today" => $w->getUpdatedOn() instanceof DateTimeValue ? $w->getUpdatedOn()->isToday() : 0, "updatedBy" => $w->getUpdatedByDisplayName(), "updatedById" => $w->getUpdatedById(), "memPath" => json_encode($w->getMembersToDisplayPath())); } $read_objects = ReadObjects::getReadByObjectList($ids, logged_user()->getId()); foreach ($object["webpages"] as &$data) { $data['isRead'] = isset($read_objects[$data['object_id']]); } } ajx_extra_data($object); }
/** * Return manager instance * * @access protected * @param void * @return LinkedObject */ function manager() { if(!($this->manager instanceof ReadObject)) $this->manager = ReadObjects::instance(); return $this->manager; } // manager
function list_files() { ajx_current("empty"); // get query parameters $start = (integer)array_var($_GET,'start'); $limit = (integer)array_var($_GET,'limit'); if (! $start) { $start = 0; } if (! $limit) { $limit = config_option('files_per_page'); } $order = array_var($_GET,'sort'); $order_dir = array_var($_GET,'dir'); $page = (integer) ($start / $limit)+1; $hide_private = !logged_user()->isMemberOfOwnerCompany(); $type = array_var($_GET,'type'); $user = array_var($_GET,'user'); // if there's an action to execute, do so if (array_var($_GET, 'action') == 'delete') { $ids = explode(',', array_var($_GET, 'objects')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); if (isset($file) && $file->canDelete(logged_user())) { try{ DB::beginWork(); $file->trash(); ApplicationLogs::createLog($file, ApplicationLogs::ACTION_TRASH); DB::commit(); $succ++; } catch(Exception $e){ DB::rollback(); $err++; } } else { $err++; } } if ($succ > 0) { flash_success(lang("success delete files", $succ)); } else { flash_error(lang("error delete files", $err)); } } else if (array_var($_GET, 'action') == 'markasread') { $ids = explode(',', array_var($_GET, 'objects')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); try { $file->setIsRead(logged_user()->getId(),true); $succ++; } catch(Exception $e) { $err ++; } // try }//for if ($succ <= 0) { flash_error(lang("error markasread files", $err)); } }else if (array_var($_GET, 'action') == 'markasunread') { $ids = explode(',', array_var($_GET, 'objects')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); try { $file->setIsRead(logged_user()->getId(),false); $succ++; } catch(Exception $e) { $err ++; } // try }//for if ($succ <= 0) { flash_error(lang("error markasunread files", $err)); } } else if (array_var($_GET, 'action') == 'zip_add') { $this->zip_add(); } else if (array_var($_GET, 'action') == 'archive') { $ids = explode(',', array_var($_GET, 'ids')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); if (isset($file) && $file->canEdit(logged_user())) { try{ DB::beginWork(); $file->archive(); ApplicationLogs::createLog($file, ApplicationLogs::ACTION_ARCHIVE); DB::commit(); $succ++; } catch(Exception $e){ DB::rollback(); $err++; } } else { $err++; } } if ($succ > 0) { flash_success(lang("success archive objects", $succ)); } else { flash_error(lang("error archive objects", $err)); } } Hook::fire('classify_action', null, $ret); $join_params = null; if ($order == ProjectFiles::ORDER_BY_POSTTIME) { $order = '`created_on`'; } else if ($order == ProjectFiles::ORDER_BY_MODIFYTIME) { $order = '`updated_on`'; } else if ($order == ProjectFiles::ORDER_BY_SIZE) { $order = '`jt`.`filesize`'; $join_params = array( 'table' => ProjectFileRevisions::instance()->getTableName(), 'jt_field' => 'object_id', 'j_sub_q' => "SELECT max(`x`.`object_id`) FROM ".ProjectFileRevisions::instance()->getTableName()." `x` WHERE `x`.`file_id` = `e`.`object_id`" ); } else { $order = '`name`'; } // if $extra_conditions = $hide_private ? 'AND `is_visible` = 1' : ''; $context = active_context(); $objects = ProjectFiles::instance()->listing(array( "order"=>$order, "order_dir" => $order_dir, "extra_conditions"=> $extra_conditions, "join_params"=> $join_params, "start"=> $start, "limit"=> $limit )); $custom_properties = CustomProperties::getAllCustomPropertiesByObjectType(ProjectFiles::instance()->getObjectTypeId()); // prepare response object $listing = array( "totalCount" => $objects->total, "start" => $start, "objType" => ProjectFiles::instance()->getObjectTypeId(), "files" => array(), ); if (is_array($objects->objects)) { $index = 0; $ids = array(); foreach ($objects->objects as $o) { $coName = ""; $coId = $o->getCheckedOutById(); if ($coId != 0) { if ($coId == logged_user()->getId()) { $coName = "self"; } else { $coUser = Contacts::findById($coId); if ($coUser instanceof Contact) { $coName = $coUser->getUsername(); } else { $coName = ""; } } } if ($o->isMP3()) { $songname = $o->getProperty("songname"); $artist = $o->getProperty("songartist"); $album = $o->getProperty("songalbum"); $track = $o->getProperty("songtrack"); $year = $o->getProperty("songyear"); $duration = $o->getProperty("songduration"); $songInfo = json_encode(array($songname, $artist, $album, $track, $year, $duration, $o->getDownloadUrl(), $o->getFilename(), $o->getId())); } else { $songInfo = array(); } $ids[] = $o->getId(); $values = array( "id" => $o->getId(), "ix" => $index++, "object_id" => $o->getId(), "ot_id" => $o->getObjectTypeId(), "name" => $o->getObjectName(), "type" => $o->getTypeString(), "mimeType" => $o->getTypeString(), "createdBy" => clean($o->getCreatedByDisplayName()), "createdById" => $o->getCreatedById(), "dateCreated" => $o->getCreatedOn() instanceof DateTimeValue ? ($o->getCreatedOn()->isToday() ? format_time($o->getCreatedOn()) : format_datetime($o->getCreatedOn())) : '', "dateCreated_today" => $o->getCreatedOn() instanceof DateTimeValue ? $o->getCreatedOn()->isToday() : 0, "updatedBy" => clean($o->getUpdatedByDisplayName()), "updatedById" => $o->getUpdatedById(), "dateUpdated" => $o->getUpdatedOn() instanceof DateTimeValue ? ($o->getUpdatedOn()->isToday() ? format_time($o->getUpdatedOn()) : format_datetime($o->getUpdatedOn())) : '', "dateUpdated_today" => $o->getUpdatedOn() instanceof DateTimeValue ? $o->getUpdatedOn()->isToday() : 0, "icon" => $o->getTypeIconUrl(), "size" => format_filesize($o->getFileSize()), "url" => $o->getOpenUrl(), "manager" => get_class($o->manager()), "checkedOutByName" => $coName, "checkedOutById" => $coId, "isModifiable" => $o->isModifiable() && $o->canEdit(logged_user()), "modifyUrl" => $o->getModifyUrl(), "songInfo" => $songInfo, "ftype" => $o->getType(), "url" => $o->getUrl(), "memPath" => json_encode($o->getMembersToDisplayPath()), ); if ($o->isMP3()) { $values['isMP3'] = true; } Hook::fire('add_classification_value', $o, $values); foreach ($custom_properties as $cp) { $cp_value = CustomPropertyValues::getCustomPropertyValue($o->getId(), $cp->getId()); $values['cp_'.$cp->getId()] = $cp_value instanceof CustomPropertyValue ? $cp_value->getValue() : ''; } $listing["files"][] = $values; } $read_objects = ReadObjects::getReadByObjectList($ids, logged_user()->getId()); foreach($listing["files"] as &$data) { $data['isRead'] = isset($read_objects[$data['object_id']]); } ajx_extra_data($listing); tpl_assign("listing", $listing); }else{ throw new Error("Not array", $code); } }
/** * Prepares return object for a list of emails and messages * * @param array $totMsg * @param integer $start * @param integer $limit * @return array */ private function prepareObject($totMsg, $start, $limit, $total) { $object = array("totalCount" => $total, "start" => $start, "messages" => array()); $custom_properties = CustomProperties::getAllCustomPropertiesByObjectType(ProjectMessages::instance()->getObjectTypeId()); $ids = array(); for ($i = 0; $i < $limit; $i++) { if (isset($totMsg[$i])) { $msg = $totMsg[$i]; if ($msg instanceof ProjectMessage) { $text = $msg->getText(); if (strlen($text) > 100) { $text = substr_utf($text, 0, 100) . "..."; } $object["messages"][$i] = array("id" => $i, "ix" => $i, "object_id" => $msg->getId(), "ot_id" => $msg->getObjectTypeId(), "type" => $msg->getObjectTypeName(), "name" => $msg->getObjectName(), "text" => html_to_text($text), "date" => $msg->getUpdatedOn() instanceof DateTimeValue ? $msg->getUpdatedOn()->isToday() ? format_time($msg->getUpdatedOn()) : format_datetime($msg->getUpdatedOn()) : '', "is_today" => $msg->getUpdatedOn() instanceof DateTimeValue ? $msg->getUpdatedOn()->isToday() : 0, "userId" => $msg->getCreatedById(), "userName" => $msg->getCreatedByDisplayName(), "updaterId" => $msg->getUpdatedById() ? $msg->getUpdatedById() : $msg->getCreatedById(), "updaterName" => $msg->getUpdatedById() ? $msg->getUpdatedByDisplayName() : $msg->getCreatedByDisplayName(), "memPath" => json_encode($msg->getMembersIdsToDisplayPath())); $ids[] = $msg->getId(); foreach ($custom_properties as $cp) { $object["messages"][$i]['cp_' . $cp->getId()] = get_custom_property_value_for_listing($cp, $msg); } } } } $read_objects = ReadObjects::getReadByObjectList($ids, logged_user()->getId()); foreach ($object["messages"] as &$data) { $data['isRead'] = isset($read_objects[$data['object_id']]); } return $object; }
/** * This function will return paginated result. Result is an array where first element is * array of returned object and second populated pagination object that can be used for * obtaining and rendering pagination data using various helpers. * * Items and pagination array vars are indexed with 0 for items and 1 for pagination * because you can't use associative indexing with list() construct * * @access public * @param array $arguments Query argumens (@see find()) Limit and offset are ignored! * @param integer $items_per_page Number of items per page * @param integer $current_page Current page number * @return array */ function paginate($arguments = null, $items_per_page = 10, $current_page = 1) { if (isset($this) && instance_of($this, 'ReadObjects')) { return parent::paginate($arguments, $items_per_page, $current_page); } else { return ReadObjects::instance()->paginate($arguments, $items_per_page, $current_page); } // if }
function list_files() { ajx_current("empty"); // get query parameters $start = (int) array_var($_GET, 'start'); $limit = (int) array_var($_GET, 'limit'); if (!$start) { $start = 0; } if (!$limit) { $limit = config_option('files_per_page'); } $order = array_var($_GET, 'sort'); $order_dir = array_var($_GET, 'dir'); $page = (int) ($start / $limit) + 1; $hide_private = !logged_user()->isMemberOfOwnerCompany(); $type = array_var($_GET, 'type'); $user = array_var($_GET, 'user'); // if there's an action to execute, do so if (array_var($_GET, 'action') == 'delete') { $ids = explode(',', array_var($_GET, 'objects')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); if (isset($file) && $file->canDelete(logged_user())) { try { DB::beginWork(); $file->trash(); DB::commit(); ApplicationLogs::createLog($file, ApplicationLogs::ACTION_TRASH); $succ++; } catch (Exception $e) { DB::rollback(); $err++; } } else { if (!$file instanceof ProjectFile) { evt_add("popup", array('title' => lang('error'), 'message' => lang("file dnx"))); } else { if (!$file->canDelete(logged_user())) { evt_add("popup", array('title' => lang('error'), 'message' => lang("cannot delete file", $file->getObjectName()))); } } $err++; } } if ($succ > 0) { flash_success(lang("success delete files", $succ)); } else { flash_error(lang("error delete files", $err)); } } else { if (array_var($_GET, 'action') == 'markasread') { $ids = explode(',', array_var($_GET, 'objects')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); try { $file->setIsRead(logged_user()->getId(), true); $succ++; } catch (Exception $e) { $err++; } // try } //for if ($succ <= 0) { flash_error(lang("error markasread files", $err)); } } else { if (array_var($_GET, 'action') == 'markasunread') { $ids = explode(',', array_var($_GET, 'objects')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); try { $file->setIsRead(logged_user()->getId(), false); $succ++; } catch (Exception $e) { $err++; } // try } //for if ($succ <= 0) { flash_error(lang("error markasunread files", $err)); } } else { if (array_var($_GET, 'action') == 'zip_add') { $this->zip_add(); } else { if (array_var($_GET, 'action') == 'archive') { $ids = explode(',', array_var($_GET, 'ids')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); if (isset($file) && $file->canEdit(logged_user())) { try { DB::beginWork(); $file->archive(); DB::commit(); ApplicationLogs::createLog($file, ApplicationLogs::ACTION_ARCHIVE); $succ++; } catch (Exception $e) { DB::rollback(); $err++; } } else { $err++; } } if ($succ > 0) { flash_success(lang("success archive objects", $succ)); } else { flash_error(lang("error archive objects", $err)); } } } } } } Hook::fire('classify_action', null, $ret); $join_params = null; $select_columns = null; $extra_conditions = ""; if (strpos($order, 'p_') == 1) { $cpId = substr($order, 3); $order = 'customProp'; } if ($order == ProjectFiles::ORDER_BY_POSTTIME) { $order = '`created_on`'; } else { if ($order == ProjectFiles::ORDER_BY_MODIFYTIME) { $order = '`updated_on`'; } else { if ($order == ProjectFiles::ORDER_BY_SIZE) { $order = '`jt`.`filesize`'; $join_params = array('table' => ProjectFileRevisions::instance()->getTableName(), 'jt_field' => 'file_id', 'e_field' => 'object_id'); $extra_conditions .= " AND `jt`.`object_id` = (SELECT max(`x`.`object_id`) FROM " . TABLE_PREFIX . "project_file_revisions `x` WHERE `x`.`file_id` = `e`.`object_id`)"; } else { if ($order == 'customProp') { $order = 'IF(ISNULL(jt.value),1,0),jt.value'; $join_params['join_type'] = "LEFT "; $join_params['table'] = "" . TABLE_PREFIX . "custom_property_values"; $join_params['jt_field'] = "object_id"; $join_params['e_field'] = "object_id"; $join_params['on_extra'] = "AND custom_property_id = " . $cpId; $extra_conditions .= " AND ( custom_property_id = " . $cpId . " OR custom_property_id IS NULL)"; $select_columns = array("DISTINCT o.*", "e.*"); } else { $order = '`name`'; } } } } // if $extra_conditions .= $hide_private ? 'AND `is_visible` = 1' : ''; // filter attachments of other people if not filtering $tmp_mids = array(); foreach (active_context() as $selection) { if ($selection instanceof Member) { $d = $selection->getDimension(); if ($d instanceof Dimension && $d->getIsManageable()) { $tmp_mids[] = $selection->getId(); } } } if (count($tmp_mids) == 0) { if (Plugins::instance()->isActivePlugin('mail')) { $extra_conditions .= " AND IF(e.mail_id=0, true, EXISTS (SELECT mac.contact_id FROM " . TABLE_PREFIX . "mail_account_contacts mac \r\n\t\t\t\t\tWHERE mac.contact_id=o.created_by_id AND mac.account_id=(SELECT mc.account_id FROM " . TABLE_PREFIX . "mail_contents mc WHERE mc.object_id=e.mail_id)))"; } } Hook::fire("listing_extra_conditions", null, $extra_conditions); $only_count_result = array_var($_GET, 'only_result', false); $context = active_context(); $objects = ProjectFiles::instance()->listing(array("order" => $order, "order_dir" => $order_dir, "extra_conditions" => $extra_conditions, "show_only_member_objects" => user_config_option('show_only_member_files'), 'count_results' => false, 'only_count_results' => $only_count_result, "join_params" => $join_params, "start" => $start, "limit" => $limit, "select_columns" => $select_columns)); $custom_properties = CustomProperties::getAllCustomPropertiesByObjectType(ProjectFiles::instance()->getObjectTypeId()); // prepare response object $listing = array("totalCount" => $objects->total, "start" => $start, "objType" => ProjectFiles::instance()->getObjectTypeId(), "files" => array()); if (is_array($objects->objects)) { $index = 0; $ids = array(); foreach ($objects->objects as $o) { $coName = ""; $coId = $o->getCheckedOutById(); if ($coId != 0) { if ($coId == logged_user()->getId()) { $coName = "self"; } else { $coUser = Contacts::findById($coId); if ($coUser instanceof Contact) { $coName = $coUser->getObjectName(); } else { $coName = ""; } } } if ($o->isMP3()) { $songname = $o->getProperty("songname"); $artist = $o->getProperty("songartist"); $album = $o->getProperty("songalbum"); $track = $o->getProperty("songtrack"); $year = $o->getProperty("songyear"); $duration = $o->getProperty("songduration"); $songInfo = json_encode(array($songname, $artist, $album, $track, $year, $duration, $o->getDownloadUrl(), $o->getFilename(), $o->getId())); } else { $songInfo = array(); } $ids[] = $o->getId(); $values = array("id" => $o->getId(), "ix" => $index++, "object_id" => $o->getId(), "ot_id" => $o->getObjectTypeId(), "name" => $o->getObjectName(), "type" => $o->getTypeString(), "mimeType" => $o->getTypeString(), "createdBy" => clean($o->getCreatedByDisplayName()), "createdById" => $o->getCreatedById(), "dateCreated" => $o->getCreatedOn() instanceof DateTimeValue ? $o->getCreatedOn()->isToday() ? format_time($o->getCreatedOn()) : format_datetime($o->getCreatedOn()) : '', "dateCreated_today" => $o->getCreatedOn() instanceof DateTimeValue ? $o->getCreatedOn()->isToday() : 0, "updatedBy" => clean($o->getUpdatedByDisplayName()), "updatedById" => $o->getUpdatedById(), "dateUpdated" => $o->getUpdatedOn() instanceof DateTimeValue ? $o->getUpdatedOn()->isToday() ? format_time($o->getUpdatedOn()) : format_datetime($o->getUpdatedOn()) : '', "dateUpdated_today" => $o->getUpdatedOn() instanceof DateTimeValue ? $o->getUpdatedOn()->isToday() : 0, "icon" => $o->getTypeIconUrl(), "size" => format_filesize($o->getFileSize()), "url" => $o->getOpenUrl(), "manager" => get_class($o->manager()), "checkedOutByName" => $coName, "checkedOutById" => $coId, "isModifiable" => $o->isModifiable() && $o->canEdit(logged_user()), "modifyUrl" => $o->getModifyUrl(), "songInfo" => $songInfo, "ftype" => $o->getType(), "url" => $o->getUrl(), "memPath" => json_encode($o->getMembersIdsToDisplayPath()), "genid" => gen_id()); if ($o->isMP3()) { $values['isMP3'] = true; } Hook::fire('add_classification_value', $o, $values); foreach ($custom_properties as $cp) { $values['cp_' . $cp->getId()] = get_custom_property_value_for_listing($cp, $o); } $listing["files"][] = $values; } $read_objects = ReadObjects::getReadByObjectList($ids, logged_user()->getId()); foreach ($listing["files"] as &$data) { $data['isRead'] = isset($read_objects[$data['object_id']]); } ajx_extra_data($listing); tpl_assign("listing", $listing); } else { throw new Error("Not array", $code); } }
function delete($deleteMails = false){ MailAccountContacts::deleteByAccount($this); if ($deleteMails) { session_commit(); ini_set('memory_limit', '1024M'); LinkedObjects::delete(array("(`object_id` IN (SELECT `object_id` FROM `".TABLE_PREFIX."mail_contents` WHERE `account_id` = " . DB::escape($this->getId()).")) or (`rel_object_id` IN (SELECT `object_id` FROM `".TABLE_PREFIX."mail_contents` WHERE `account_id` = " . DB::escape($this->getId())."))")); SearchableObjects::delete(array("`rel_object_id` IN (SELECT `object_id` FROM `".TABLE_PREFIX."mail_contents` WHERE `account_id` = " . DB::escape($this->getId()).") ")); ReadObjects::delete("`rel_object_id` IN (SELECT `object_id` FROM `".TABLE_PREFIX."mail_contents` WHERE `account_id` = " . DB::escape($this->getId()).") "); $account_email_ids = MailContents::findAll(array('id' => true, 'conditions' => '`account_id` = ' . DB::escape($this->getId()), 'include_trashed' => true)); if (count($account_email_ids) > 0) { MailDatas::delete('id IN ('.implode(',', $account_email_ids).')'); MailContents::delete('`account_id` = ' . DB::escape($this->getId())); } } if ($this->getIsImap()) { MailAccountImapFolders::delete('account_id = ' . $this->getId()); } parent::delete(); }
private function getTasksInGroup($conditions, $start, $limit, $join_params = null, $group_by = null) { $order = user_config_option('tasksOrderBy'); $order_dir = 'DESC'; switch ($order) { case 'name': $order_dir = 'ASC'; break; case 'assigned_to': $order = 'assigned_to_contact_id'; $order_dir = 'ASC'; break; case 'due_date': case 'start_date': case 'created_on': case 'completed_on': $order = "({$order}='0000-00-00 00:00:00'), {$order}"; $order_dir = 'ASC'; break; } //START tasks tree $list_subtasks = user_config_option('tasksShowSubtasksStructure') && !user_config_option('show_tasks_list_as_gantt'); if ($list_subtasks) { $tasks_tree = ProjectTasks::instance()->listing(array("select_columns" => array("e.object_id", "e.parent_id", "e.depth", "e.parents_path"), "extra_conditions" => $conditions, "join_params" => $join_params, "group_by" => $group_by, "count_results" => false, "raw_data" => true))->objects; if (is_array($tasks_tree)) { $root_nodes = $this->getRootNodes($tasks_tree); if (is_array($root_nodes) && count($root_nodes) > 0) { $see_roots_ids = implode(',', $root_nodes); $conditions .= " AND e.object_id IN ({$see_roots_ids})"; $total_see_roots_tasks = count($root_nodes); } else { $total_see_roots_tasks = 0; } } else { $total_see_roots_tasks = 0; } } else { $total_see_roots_tasks = 0; } //END tasks tree $tasks = ProjectTasks::instance()->listing(array("select_columns" => array("e.*", "o.*"), "extra_conditions" => $conditions, "join_params" => $join_params, "group_by" => $group_by, "start" => $start, "limit" => $limit, "order" => $order, "order_dir" => $order_dir, "count_results" => false, "raw_data" => true))->objects; $task_ids = array(); $tasks_array = array(); foreach ($tasks as $task) { $tasks_array[] = ProjectTasks::getArrayInfo($task); $task_ids[] = $task['object_id']; } $read_objects = ReadObjects::getReadByObjectList($task_ids, logged_user()->getId()); foreach ($tasks_array as &$data) { $data['isread'] = isset($read_objects[$data['id']]); } $return_array = array(); $return_array['total_roots_tasks'] = $total_see_roots_tasks; $return_array['tasks'] = $tasks_array; return $return_array; }
function delete($deleteMails = false) { MailAccountUsers::deleteByAccount($this); if ($deleteMails) { session_commit(); LinkedObjects::delete(array("(`object_id` IN (SELECT `id` FROM `" . TABLE_PREFIX . "mail_contents` WHERE `account_id` = " . DB::escape($this->getId()) . ") and `object_manager` = 'MailContents') \n\t\t\t\tor (`rel_object_id` IN (SELECT `id` FROM `" . TABLE_PREFIX . "mail_contents` WHERE `account_id` = " . DB::escape($this->getId()) . ") and `rel_object_manager` = 'MailContents')")); SearchableObjects::delete(array("`rel_object_manager` = 'MailContents' AND `rel_object_id` IN (SELECT `id` FROM `" . TABLE_PREFIX . "mail_contents` WHERE `account_id` = " . DB::escape($this->getId()) . ") ")); ReadObjects::delete("`rel_object_manager` = 'MailContents' AND `rel_object_id` IN (SELECT `id` FROM `" . TABLE_PREFIX . "mail_contents` WHERE `account_id` = " . DB::escape($this->getId()) . ") "); $account_emails = MailContents::findAll(array('conditions' => '`account_id` = ' . DB::escape($this->getId()), 'include_trashed' => true)); foreach ($account_emails as $email) { $email->delete(); } //MailContents::delete('`account_id` = ' . DB::escape($this->getId())); } if ($this->getIsImap()) { MailAccountImapFolders::delete('account_id = ' . $this->getId()); } parent::delete(); }
/** * Return manager instance * * @access protected * @param void * @return LinkedObject */ function manager() { if (!$this->manager instanceof ReadObject) { $this->manager = ReadObjects::instance(); } return $this->manager; }
/** * Populates information about read status for the * * @param $objects_list * @return unknown_type */ private function populateIsRead($objects_list) { if (is_array($objects_list) && count($objects_list) > 0 && $objects_list[0]->isReadMarkable()) { $ids = array(); $objects = array(); $manager_name = $objects_list[0]->getObjectManagerName(); for ($i = 0; $i < count($objects_list); $i++) { $ids[] = $objects_list[$i]->getId(); $objects[$objects_list[$i]->getId()] = $objects_list[$i]; $objects_list[$i]->is_read[logged_user()->getId()] = false; } if (count($ids > 0)) { $readObjects = ReadObjects::findAll(array('conditions' => 'user_id = \'' . logged_user()->getId() . '\' AND rel_object_manager = \'' . $manager_name . '\' AND rel_object_id in (' . implode(',', $ids) . ')')); for ($i = 0; $i < count($readObjects); $i++) { $object = $objects[$readObjects[$i]->getRelObjectId()]; $object->is_read[logged_user()->getId()] = $readObjects[$i]->getIsRead(); } } } }
function clearReads() { return ReadObjects::delete(array("`rel_object_id` = ?", $this->getId())); }
function clearReads() { return ReadObjects::delete(array("`rel_object_manager` = ? AND `rel_object_id` = ?", $this->getObjectManagerName(), $this->getId())); }