Exemplo n.º 1
0
 public function getOwnersByType($data)
 {
     $this->setResponseType('json');
     $result = new stdclass();
     $result->status = 'OK';
     try {
         switch ($data->type) {
             case 'EVERYBODY':
                 $result->total = 0;
                 $result->owners = array();
                 break;
             case 'USER':
                 require_once 'classes/model/Users.php';
                 $users = array();
                 $usersInstance = new Users();
                 $allUsers = $usersInstance->getAll();
                 foreach ($allUsers->data as $user) {
                     $users[] = array('OWNER_UID' => $user['USR_UID'], 'OWNER_NAME' => $user['USR_FIRSTNAME'] . ' ' . $user['USR_LASTNAME']);
                 }
                 usort($users, function ($str1, $str2) {
                     return strcmp(strtolower($str1["OWNER_NAME"]), strtolower($str2["OWNER_NAME"]));
                 });
                 $result->total = $allUsers->totalCount;
                 $result->owners = $users;
                 break;
             case 'DEPARTMENT':
                 require_once 'classes/model/Department.php';
                 require_once 'classes/model/Content.php';
                 $departments = array();
                 //SELECT
                 $criteria = new Criteria('workflow');
                 $criteria->setDistinct();
                 $criteria->addSelectColumn(DepartmentPeer::DEP_UID);
                 $criteria->addSelectColumn(ContentPeer::CON_VALUE);
                 //FROM
                 $conditions = array();
                 $conditions[] = array(DepartmentPeer::DEP_UID, ContentPeer::CON_ID);
                 $conditions[] = array(ContentPeer::CON_CATEGORY, DBAdapter::getStringDelimiter() . 'DEPO_TITLE' . DBAdapter::getStringDelimiter());
                 $conditions[] = array(ContentPeer::CON_LANG, DBAdapter::getStringDelimiter() . 'en' . DBAdapter::getStringDelimiter());
                 $criteria->addJoinMC($conditions, Criteria::LEFT_JOIN);
                 //WHERE
                 $criteria->add(DepartmentPeer::DEP_STATUS, 'ACTIVE');
                 //ORDER BY
                 $criteria->addAscendingOrderByColumn(ContentPeer::CON_VALUE);
                 $dataset = DepartmentPeer::doSelectRS($criteria);
                 $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
                 $dataset->next();
                 while ($row = $dataset->getRow()) {
                     $departments[] = array('OWNER_UID' => $row['DEP_UID'], 'OWNER_NAME' => $row['CON_VALUE']);
                     $dataset->next();
                 }
                 $result->total = DepartmentPeer::doCount($criteria);
                 $result->owners = $departments;
                 break;
             case 'GROUP':
                 require_once 'classes/model/Groupwf.php';
                 require_once 'classes/model/Content.php';
                 $groups = array();
                 //SELECT
                 $criteria = new Criteria('workflow');
                 $criteria->setDistinct();
                 $criteria->addSelectColumn(GroupwfPeer::GRP_UID);
                 $criteria->addSelectColumn(ContentPeer::CON_VALUE);
                 //FROM
                 $conditions = array();
                 $conditions[] = array(GroupwfPeer::GRP_UID, ContentPeer::CON_ID);
                 $conditions[] = array(ContentPeer::CON_CATEGORY, DBAdapter::getStringDelimiter() . 'GRP_TITLE' . DBAdapter::getStringDelimiter());
                 $conditions[] = array(ContentPeer::CON_LANG, DBAdapter::getStringDelimiter() . 'en' . DBAdapter::getStringDelimiter());
                 $criteria->addJoinMC($conditions, Criteria::LEFT_JOIN);
                 //WHERE
                 $criteria->add(GroupwfPeer::GRP_STATUS, 'ACTIVE');
                 //ORDER BY
                 $criteria->addAscendingOrderByColumn(ContentPeer::CON_VALUE);
                 $dataset = GroupwfPeer::doSelectRS($criteria);
                 $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
                 $dataset->next();
                 while ($row = $dataset->getRow()) {
                     $groups[] = array('OWNER_UID' => $row['GRP_UID'], 'OWNER_NAME' => $row['CON_VALUE']);
                     $dataset->next();
                 }
                 $result->total = GroupwfPeer::doCount($criteria);
                 $result->owners = $groups;
                 break;
         }
     } catch (Exception $error) {
         $result->status = 'ERROR';
         $result->message = $error->getMessage();
     }
     return $result;
 }
Exemplo n.º 2
0
 public function countDepartmentsRelatedByParent($criteria = null, $distinct = false, $con = null)
 {
     include_once 'lib/model/om/BaseDepartmentPeer.php';
     if ($criteria === null) {
         $criteria = new Criteria();
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     $criteria->add(DepartmentPeer::PARENT, $this->getId());
     return DepartmentPeer::doCount($criteria, $distinct, $con);
 }